C# Conversion from VB6 - Recordset
I'm wanting to convert the line to C# from VB6 and am having quite the di开发者_如何转开发fficulty doing so.
VB6 Code:
txtFields(4).Text = rsGroup.Fields(0).Value + 1
C#: (what I have so far)
txtFields4.Text = (rsGroup.Fields[0].Value) +1);
What is the correct way to do this?
@jdurman,
An example of retrieving data using a DataSet is:
public DataSet GetDate(string SqlString)
{
SqlConnection sqlConn = new SqlConnection("CONNECTION STRING GOES HERE");
DataSet ds = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(SqlString, sqlConn);
adapter.Fill(ds);
return ds;
}
public void LoopThroughDataExample(DataSet ds)
{
foreach(DataTable dt in ds)
{
foreach(DataRow dr in dt)
{
Console.WriteLine(String.Format("Value is: {0}", dr["DBColumnName"])); // Replace DBColumnName with the name of columns in the Database Table that you want to Extract.
}
}
}
I would not use a RecordSet and Use a DataSet instead. you can use the System.Data.SqlClient namespace to be able to access Databases and then you can bind controls from your DataSet, makes life alot easier, and also i would avoid doing straight copying of code from VB6. There is alot of new thing in the world of C# that you would never of had the option of using in VB6 prior.
txtFields[4].Text = rsGroup.Fields[0].Value + 1;
精彩评论