Source en VB .NET fonctionne et son equivalent en C# ne fonctionne pas ??!!
cs_othland
Messages postés298Date d'inscriptionjeudi 18 décembre 2003StatutMembreDernière intervention 9 février 2010
-
19 juil. 2007 à 23:25
cs_othland
Messages postés298Date d'inscriptionjeudi 18 décembre 2003StatutMembreDernière intervention 9 février 2010
-
20 juil. 2007 à 11:03
salut tout le monde!
j'ai un code source d'un composant webpart écrit en VB .NET et qui fonctionne correctement, j'ai voulu le traduire en C# (car j'ai besoin de ce même code mais en C#) mais le problème c'est que ça ne fontionne pas!
et comme je débute, j'ai pu trouver l'anomalie
SVP aidez moi
je pense qu'il y a qq chose d'anormal dans mon code en C# écrit en rouge!
<DefaultProperty(""), ToolboxData("<{0}:View runat=server></{0}:View>"), _
XmlRoot(Namespace:="SPSPubsAuthors")> _
Public Class View
Inherits Microsoft.SharePoint.WebPartPages.WebPart
Private strSQLserver As String = ""
Private strDatabase As String = ""
'SQL Server Name
WebPartStorage(Storage.Shared), FriendlyName("SQLServer"), _
Description("The server where pubs is installed.")> _
Property SQLServer() As String
Get
Return strSQLserver
End Get
Set(ByVal Value As String)
strSQLserver = Value
End Set
End Property
'Database Name
WebPartStorage(Storage.Shared), FriendlyName("Database"), _
Description("The database where the Enterprise Data is located.")> _
Property Database() As String
Get
Return strDatabase
End Get
Set(ByVal Value As String)
strDatabase = Value
End Set
End Property
Protected WithEvents grdNames As DataGrid
Protected WithEvents lblMessage As Label
Protected Overrides Sub CreateChildControls()
'Grid to display results
grdNames = New DataGrid
With grdNames
.Width = Unit.Percentage(100)
.HeaderStyle.Font.Name = "arial"
.HeaderStyle.Font.Size = New FontUnit(FontSize.AsUnit).Point(10)
.HeaderStyle.Font.Bold = True
.HeaderStyle.ForeColor = System.Drawing.Color.Wheat
.HeaderStyle.BackColor = System.Drawing.Color.DarkBlue
.AlternatingItemStyle.BackColor = System.Drawing.Color.LightCyan
End With
Controls.Add(grdNames)
'Label for error messages
lblMessage = New Label
With lblMessage
.Width = Unit.Percentage(100)
.Font.Name = "arial"
.Font.Size = New FontUnit(FontSize.AsUnit).Point(10)
.Text = ""
End With
Controls.Add(lblMessage)
End Sub
Protected Overrides Sub RenderWebPart _
(ByVal output As System.Web.UI.HtmlTextWriter)
Dim objDataSet As System.Data.DataSet
'Set up connection string from custom properties
Dim strConnection As String
strConnection += "Password=" & Password
strConnection += ";Persist Security Info=True;User ID="
strConnection += UserName + ";Initial Catalog=" + Database
strConnection += ";Data Source=" + SQLServer
'Query pubs database
Dim strSQL As String = "select * from authors"
'Try to run the query
Try
With New System.Data.SqlClient.SqlDataAdapter
objDataSet = New DataSet("root")
.SelectCommand = _
New System.Data.SqlClient.SqlCommand(strSQL, _
New System.Data.SqlClient.SqlConnection(strConnection))
.Fill(objDataSet, "authors")
End With
Catch ex As Exception
lblMessage.Text = ex.Message
Exit Sub
End Try
'Bind to grid
Try
With grdNames
.DataSource = objDataSet
.DataMember = "authors"
.DataBind()
End With
Catch ex As Exception
lblMessage.Text = ex.Message
Exit Sub
End Try
'Draw the controls in an HTML table
With output
.Write("\")
.Write(\"----
\")
.Write(\"")
grdNames.RenderControl(output)
.Write(", \")
.Write(\"\")
.Write(\"----
\")
.Write(\"")
lblMessage.RenderControl(output)
.Write(", \")
.Write(\"\")
.Write("
")
End With
End Sub
End Class
////////////
////////////
code en C# :
///////////
using System;
using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml.Serialization;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebPartPages;
namespace WebPartLibrary1
{
[DefaultProperty(""),
ToolboxData("<{0}:container runat=server></{0}:container>"),
XmlRoot(Namespace="essaie001")]
public class container : Microsoft.SharePoint.WebPartPages.WebPart
{
private string strSQLserver = "";
private string strDatabase = "";
//SQL Server Name
[Browsable(true), Category("Miscellaneous"),
DefaultValue(""),
WebPartStorage(Storage.Shared),
FriendlyName("SQLServer"),
Description("The server where pubs is installed.")]
public string SERVER
{
get
{
return strSQLserver;
}
set
{
strSQLserver = value;
}
}
//Database Name
[Browsable(true), Category("Miscellaneous"),
DefaultValue(""),
WebPartStorage(Storage.Shared),
FriendlyName("Database"),
Description("The database where the Enterprise Data is located.")]
public string DataBase
{
get
{
return strDatabase;
}
set
{
strDatabase = value;
}
}
jrivet
Messages postés7392Date d'inscriptionmercredi 23 avril 2003StatutMembreDernière intervention 6 avril 201260 20 juil. 2007 à 07:58
Salut,
"je pense qu'il y a qq chose d'anormal dans mon code en C# écrit en rouge!" Tu n'a rien mis en rouge ou alors j'ai encore les yeux dans le brouillard.
jrivet
Messages postés7392Date d'inscriptionmercredi 23 avril 2003StatutMembreDernière intervention 6 avril 201260 20 juil. 2007 à 08:47
Re,
salut [auteurdetail.aspx?ID=647037 mortalino], pas encore couché??
Non je suis sur que je ne suis pas daltonien la preuve ma signature (réponse acceptée) est verte comme le smileys a cote
cs_othland
Messages postés298Date d'inscriptionjeudi 18 décembre 2003StatutMembreDernière intervention 9 février 20101 20 juil. 2007 à 11:03
bonjour
désolé, la partie qui censée être en rouge est celle là :
/////
DataSet objDataSet;
//Set up connection string from custom properties
string strConnection;
strConnection = "Data Source=" + SERVER;
strConnection += ";Initial Catalog=" + DataBase;
strConnection += ";Integrated Security=True";
//Query pubs database
string strSQL = "select * from authors";
//Try to run the query
try
{
objDataSet = new DataSet("root");
SqlConnection conn = new SqlConnection(strConnection);
SqlDataAdapter adapter = new SqlDataAdapter(strSQL,conn);
adapter.Fill(objDataSet,"authors");
}
catch (Exception ex)
{
lblMessage.Text = ex.Message;
}
//Bind to grid
try
{
grdNames.DataSource = objDataSet;
grdNames.DataMember = "authors";
grdNames.DataBind();
///////
je ne sais pas ce qui se passe de mon coté, mais dès que change la couleur d'une partie du texte, ma question ne se poste pas!!
j'ai besoin de votre aides!
merci