'Recordset to Dataset conversion
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?
Solution 1:[1]
The near most object to recordset in ado.net is reader. Reader opens a forward only read only cursor and allows you to read the records. There is a basic difference between recordset and dataset.
Dataset is in-memory full copy of queried data. Once you fetch data in dataset, it does not require the connection whereas the recordset requires the connection. If you do not want to move forward and backward through your results, you should try reader. You will be able to use similar syntax to fetch data from reader.
Solution 2:[2]
You can try something like this:-
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;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Murtuza Kabul |
| Solution 2 | shA.t |
