Converting the DataTable type into an ADO Recordset

  • Thread starter Thread starter C Newby
  • Start date Start date
C

C Newby

I have a C# type that exposes one of its properties as a DataTable.
Unfortunately, i need to use this type from a COM application ( an ASP page
to be accurate ). So I have registered my type with Regasm and can create it
and use it just fine...except when I need to reference the DataTable
property. I imagine that because ADO.NET isn't registered for COM the
property type cannot be resolved? Eitherway ... unless there is something
very simple that i am missing, I have begun writing a method that will
return a legacy ADO recordset from my C# type.

Essentially, i would like to take the DataTable object I already have and
convert it into a disconnected recordset.

So far though, I have had some issues. For example, I cannot figure out how
to call the Open method of the recordset. I keep getting "argument out of
range, etc." errors when i call it such as:

recordset.Open( null, null, ADOR.CursorTypeEnum.adOpenDynamic,
ADOR.LockTypeEnum.adLockOptimistic, 0 );

Further ahead in my code i have the following:

foreach( DataRow row in table.Rows )
{
recordset.AddNew( table.Columns, row.ItemArray );
}

Of course, I haven't been able to step through to this point yet, but I
suspect i will encounter more problems.

What am I doing wrong so far?
Is registering System.Data for COM a reasonable consideration?
Is there an easier way to do this?

Anyway ... All comments are apreciated. TIA//
 
I generally don't communicate with the dark side (those using C#) ;), but I
wrote an article that discussed many of these ADO to ADO.NET interchange
issues. See http://www.betav.com/msdn_magazine.htm (Doing the Impossible
(Again).

hth

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Hey Bill, thanks for the help. I downloaded your code and hooked it all up.
Unfortunately, I'm getting a "The root element is missing." error when
execution gets to the line : rdr.MoveToContent() in the sub HackADOXml.

Upon inspection I can see that TransformData is returning a 3 character
stream...meaning the transform isn't working.

So what's different right? Well, I can run your test app fine. But two
things, A) I'm not using oleDb to fill my initial DataSet, B) in fact I am
filling a custom DataSet manually from a SqlDataReader. Now when I say
"custom" I don't mean that it's a derived class or anyhing like that. It's
the System.Data.DataSet type and I'm giving it a DataTable that I have built
from the Reader, that being inclusive of the Reader's columns and rows.

I realize your code is "AS IS", and I have not yet inspected the results of
the call to ds.WriteXml in the TransformData routine for differences between
your test app and my app.

Basically i was just wondering if you knew off the top of your head.
Otherwise don't sweat it, but of couse any comments are apreciated.

Thanks again for your help.
 
Bill, I looked at the different documents coming from ds.WriteXml in the
TransformData ( from your test app, and from my app ), and as you might
expect they appear identical. With one exception! I named my dataset
differently. So i changed the XSLT and things are working. Thanks again.
 
Back
Top