Open persisted ADODB recordset in ADO.Net DataSet

D

Dan Reber

The below code is what I put together to open a XML persisted ADODB 2.8
recordset in an ADO.Net v2 DataSet. My question is if the below code the
best why to go about this.

Thanks

Dan Reber
ADODB.Recordset rs = new ADODB.Recordset();

rs.Open(fileName, Type.Missing, CursorTypeEnum.adOpenStatic,
LockTypeEnum.adLockBatchOptimistic, -1);

try

{

DataSet myDataSet = new DataSet();

OleDbDataAdapter adapter = new OleDbDataAdapter();

adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;

int count = adapter.Fill(myDataSet, rs, "ADODB.RecordSet");

return myDataSet;

}

catch (Exception e)

{

Console.Write(e.ToString());

return null;

}
 
D

Dan Reber

Correct, I want to open a recordset that was saved in ADO 2.8 (Not ADO.NET)
in a ADO.NET Dataset.

Dan
 
R

RobinS

Ok, I'm not sure I can help with that. What happens when you run your
code?
Does it work?

Robin S.
--------------------------------
 
T

Teemu Keiski

Essentially, getting a recordset into ADO.NEt DataSet involves
OleDbDataAdapter to load DataSet from the recordset.

See: http://support.microsoft.com/kb/310349

Now, if you have the RS as XML, you could instantiate Recordset in .NEt code
(you need reference to ADO library), load the XML to it and then use
OleDbdataAdapter to load that into a DataSet. Of course, if you already have
a COM component returning that recordset, you don't need to persist it on
disk etc


--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net
 
R

RobinS

Thanks for the info; I didn't know you could do that. So now I guess the
question is if the OP's code actually works, because it seems very similar
to the MSDN article.

Robin S.
-----------------------------
 
D

Dan Reber

Thanks Teemu, looks like I did it the correct way. I was just checking to
make sure there wasn't an alternative that was more efficient. By the way,
the reason why I am doing it this way is so I can convert my application
from VB 6 to C# in phases. I already have a process that creates ADO 2.8
recordsets and persists them back to the database, I want to use that
functionality while I convert other parts of the application to C#.

Regards,

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top