1

I am converting VB6 code to C# so far the conversion goes fine but I was just confused with Recordset conversion to Dataset so far I converted and assigned the recordset data using dataset as follows

String strData = ds.Tables[0].Rows[0]["Col"].ToString(); 
//this is in VB6 code rs!Col

Is this conversion correct, if so I am having some recordset as follows

double d = rs(somestring).Value // before this a select query executed

How can I convert this using dataset

double d= double.Parse(ds.Tables[0].Rows[0]["someString"].ToString());

Also rs.Fields(col)

Is it correct or any other?

4

2 回答 2

0

你可以尝试这样的事情: -

ADODB.Connection oConn = new ADODB.Connection();
oConn.Open("Connection String", "", "", 0);
string strQuery = "";//Your select query or the query through which you are fetching data from database";
ADODB.Recordset rs = new ADODB.Recordset();
System.Data.OleDb.OleDbDataAdapter adapter = new System.Data.OleDb.OleDbDataAdapter();
DataTable dt = new DataTable();
rs.Open(strQuery, " Connection String,                ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, 1);
adapter.Fill(dt, rs);
return dt;
于 2013-03-16T09:30:42.663 回答
0

ado.net 中最接近记录集的对象是阅读器。阅读器打开一个只进只读游标并允许您阅读记录。记录集和数据集之间有一个基本的区别。

数据集是查询数据的内存完整副本。在数据集中获取数据后,它不需要连接,而记录集需要连接。如果您不想在结果中前后移动,您应该尝试阅读器。您将能够使用类似的语法从阅读器中获取数据。

于 2013-03-16T09:34:14.573 回答