Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code Conversion Challenge!

Status
Not open for further replies.

nickmollberg

Programmer
Aug 2, 2004
29
0
0
US
Fame! Glory! Prizes!

Well, ok... none of those things, but I will be very grateful.:)

I need to convert the code below from vb into c#...
I'm trying to do it manually, but some of the syntax is tripping me up.

Is there a way to do this easily?


Sub BindTitle()
Dim ds As New DataSet
Dim sqlStmt As String = "SELECT * FROM Appt"

Dim conString As String = "server=cluster-sql;database=XCS_HciDev;uid=sa;pwd=pass;"
Dim myda As SqlDataAdapter = New SqlDataAdapter(sqlStmt, conString)
myda.Fill(ds, "Table")
Dim slist As SortedList = New SortedList
Dim i As Integer
Dim dr As DataRow
For Each dr In ds.Tables(0).Rows
If Not slist.ContainsValue(dr("UserId")) Then
slist.Add(dr("ApptSys"), dr("UserId"))
End If
Next
DataList1.DataSource = slist.GetValueList
DataList1.DataBind()
End Sub
Function getEmp(ByVal UserId As String) As DataSet
Dim ds As New DataSet
Dim sqlStmt As String = "SELECT * FROM Appt where UserId=" & "'" & UserId & "'"
Dim conString As String = "server=cluster-sql;database=XCS_HciDev;uid=sa;pwd=pass;"
Dim myda As SqlDataAdapter = New SqlDataAdapter(sqlStmt, conString)
myda.Fill(ds, "Table")
Return ds
End Function


Private Sub DataList1_ItemDataBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound
Dim Titlelabel As Label = e.Item.FindControl("lblETitle")
Dim strEmpTitle As String = Titlelabel.Text
CType(e.Item.FindControl("Datagrid1"), DataGrid).DataSource = getEmp(strEmpTitle)
CType(e.Item.FindControl("Datagrid1"), DataGrid).DataBind()
End Sub
 
Using the Instant C# VB.NET to C# converter ( I get:

//TODO: INSTANT C# TODO TASK: Insert the following converted event handlers at the end of the 'InitializeComponent' method for forms or into a constructor for other classes:
//DataList1.ItemDataBound += new System.Web.UI.WebControls.DataListItemEventHandler(DataList1_ItemDataBound);

public void BindTitle()
{
DataSet ds = new DataSet();
string sqlStmt = "SELECT * FROM Appt";

string conString = "server=cluster-sql;database=XCS_HciDev;uid=sa;pwd=pass;";
SqlDataAdapter myda = new SqlDataAdapter(sqlStmt, conString);
myda.Fill(ds, "Table");
SortedList slist = new SortedList();
int i = 0;
//INSTANT C# NOTE: Commented this declaration since looping variables in 'foreach' loops are declared in the 'foreach' header in C#
// DataRow dr = null;
foreach (DataRow dr in ds.Tables[0].Rows)
{
if (! (slist.ContainsValue(dr["UserId"])))
{
slist.Add(dr["ApptSys"], dr["UserId"]);
}
}
DataList1.DataSource = slist.GetValueList();
DataList1.DataBind();
}
public DataSet getEmp(string UserId)
{
DataSet ds = new DataSet();
string sqlStmt = "SELECT * FROM Appt where UserId=" + "'" + UserId + "'";
string conString = "server=cluster-sql;database=XCS_HciDev;uid=sa;pwd=pass;";
SqlDataAdapter myda = new SqlDataAdapter(sqlStmt, conString);
myda.Fill(ds, "Table");
return ds;
}

//INSTANT C# NOTE: This method is an event handler
//ORIGINAL LINE: Private Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound
private void DataList1_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
Label Titlelabel = e.Item.FindControl("lblETitle");
string strEmpTitle = Titlelabel.Text;
((DataGrid)(e.Item.FindControl("Datagrid1"))).DataSource = getEmp(strEmpTitle);
((DataGrid)(e.Item.FindControl("Datagrid1"))).DataBind();
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top