简体   繁体   中英

C# Conversion from VB6 - Recordset

I'm wanting to convert the line to C# from VB6 and am having quite the difficulty 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM