471,620 Members | 1,232 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,620 software developers and data experts.

Populating disconnected ADODB.Recordset with System.Data.DataTable data.

I need to support a VB6 application that will be receiving
disconnected ADODB.Recordset from out DotNet solution. Our dotnet
solution deals with System.Data.DataTable. I need to populate a
disconnected ADODB.Recordset from System.Data.DataTable data. Below
is the source code I am implementing to test the process. I do not
get any error, that I can see. The problem I have is that at the end,
the recordset seems to be empty. Any suggestions are very much
appreciated. At this moment I do not know what to do.
Thank you so much for the time and effort you may spend on this
private bool testConvertDT_RS()
System.Data.DataTable dt;
ADODB.Recordset rs;

// create dummy data table.
dt = PopulateDataTable( );

// attempt to populate disconnected ADODB.Recordset
with System.Data.DataTable data
rs = ConvertToRS ( dt );

if( null == rs )
throw new Exception(" Recordset is null.");

if( 0 == rs.Fields.Count )
throw new Exception(" Recordset Field count is zero.");

return true;
private System.Data.DataTable PopulateDataTable()

System.Data.DataTable dt = new System.Data.DataTable();
System.Data.DataRow dr;
string[,] ColValues = {{"R1-C1", "R2-C1", "R3-C1", "R4-C1", "R5-C1"}
, {"R1-C2", "R2-C2", "R3-C2", "R4-C2", "R5-C2"} ,
{"R1-C3", "R2-C3", "R3-C3", "R4-C3", "R5-C3"}};

dt.Columns.Add(new System.Data.DataColumn("Column01",
dt.Columns.Add(new System.Data.DataColumn("Column02",
dt.Columns.Add(new System.Data.DataColumn("Column03",
for( int i = 0 ; i < 5 ; i++ )
dr = dt.NewRow();
for( int n = 0 ; n < 3 ; n++ )
dr[n] = ColValues[ n, i];
return dt;
private ADODB.Recordset ConvertToRS(System.Data.DataTable dt)
ADODB.Recordset rs = new ADODB.Recordset();


rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient;
rs.ActiveConnection = null;

for( int i = 0; i < dt.Columns.Count; i++)
rs.Fields.Append( dt.Columns[i].ColumnName,
null );
rs.Open( Type.Missing,
foreach(System.Data.DataRow dr in dt.Rows)
rs.AddNew(Type.Missing, Type.Missing);

for( int n = 0; n < dt.Columns.Count; n++)
rs.Fields[n].Value = dr[n];

rs.Update(Type.Missing, Type.Missing);


return rs;

catch(Exception e)
throw e;

Jul 21 '05 #1
0 2663

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Channing Jones | last post: by
reply views Thread by Screaming Eagles 101 | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
1 post views Thread by ZEDKYRIE | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.