traversing strongly typed DataSet

C

Corey Wirun

Hi Gang,

The latest in a string of messages dealing with Strongly Typed DataSets.
I've got a Strongly Typed DataSet 'filled', but I cannot seem to figure out
how to traverse it.

My typed DataSet is called 'RPDCY_TDataSet'. It has three columns: TAG,
SRC_TAG, DST_TAG. The class was generated with xsd.exe from an XML Schema
file (scraped from a database table):

RPDCY_TDataSet dsData = new RPDCY_TDataSet();
int nRows = daNew.Fill( dsData, "DATA" ); // daNew is an
OleDbDataAdapter. nRows = 55

foreach ( DataTable tbl in dsData.Tables )
DiagnosticLog.Debug( tbl.TableName ); // prints RPDCY_T and DATA

DiagnosticLog.Debug( "# rows = " + dsData.Tables[
"DATA" ].Rows.Count.ToString() ); // prints 55 rows
DiagnosticLog.Debug( "# rows = " + dsData.RPDCY_T.Rows.Count.ToString() );
// prints 0 rows, not expected

foreach ( RPDCY_TDataSet.RPDCY_TRow row in dsData.RPDCY_T.Rows ) //
doesn't execute anything - no rows
DiagnosticLog.Debug( row.TAG.ToString() + " " + row.SRC_TAG.ToString() +
" " + row.DST_TAG.ToString() );

So am I doing something wrong when referencing my Rows of my types DataSet
class?

Thanks for any advice!
Corey.
 
D

David Browne

Corey Wirun said:
Hi Gang,

The latest in a string of messages dealing with Strongly Typed DataSets.
I've got a Strongly Typed DataSet 'filled', but I cannot seem to figure out
how to traverse it.

My typed DataSet is called 'RPDCY_TDataSet'. It has three columns: TAG,
SRC_TAG, DST_TAG. The class was generated with xsd.exe from an XML Schema
file (scraped from a database table):

RPDCY_TDataSet dsData = new RPDCY_TDataSet();
int nRows = daNew.Fill( dsData, "DATA" ); // daNew is an
OleDbDataAdapter. nRows = 55

foreach ( DataTable tbl in dsData.Tables )
DiagnosticLog.Debug( tbl.TableName ); // prints RPDCY_T and DATA

DiagnosticLog.Debug( "# rows = " + dsData.Tables[
"DATA" ].Rows.Count.ToString() ); // prints 55 rows
DiagnosticLog.Debug( "# rows = " +
dsData.RPDCY_T.Rows.Count.ToString() );
// prints 0 rows, not expected

foreach ( RPDCY_TDataSet.RPDCY_TRow row in dsData.RPDCY_T.Rows ) //
doesn't execute anything - no rows
DiagnosticLog.Debug( row.TAG.ToString() + " " + row.SRC_TAG.ToString() +
" " + row.DST_TAG.ToString() );

So am I doing something wrong when referencing my Rows of my types DataSet
class?

You will find that you now have 2 tables in the dataset. Your
DataAdapter.Fill created a new table instead of filling the existing one.
This is an annoying "feature" of datasets, it's really easy to add a new
table using a DataAdapter. For typed datasets you almost never want to do
that.

use
daNew.Fill( dsData, "RPDCY_T" );
or
daNew.Fill( dsData, dsData.RPDCY_T.Rows);

instead.

David
 
C

Corey Wirun

Once more, the Grasshopper is humbled by the Master.

Thanks David.
Corey.

David Browne said:
Corey Wirun said:
Hi Gang,

The latest in a string of messages dealing with Strongly Typed DataSets.
I've got a Strongly Typed DataSet 'filled', but I cannot seem to figure out
how to traverse it.

My typed DataSet is called 'RPDCY_TDataSet'. It has three columns: TAG,
SRC_TAG, DST_TAG. The class was generated with xsd.exe from an XML Schema
file (scraped from a database table):

RPDCY_TDataSet dsData = new RPDCY_TDataSet();
int nRows = daNew.Fill( dsData, "DATA" ); // daNew is an
OleDbDataAdapter. nRows = 55

foreach ( DataTable tbl in dsData.Tables )
DiagnosticLog.Debug( tbl.TableName ); // prints RPDCY_T and DATA

DiagnosticLog.Debug( "# rows = " + dsData.Tables[
"DATA" ].Rows.Count.ToString() ); // prints 55 rows
DiagnosticLog.Debug( "# rows = " +
dsData.RPDCY_T.Rows.Count.ToString() );
// prints 0 rows, not expected

foreach ( RPDCY_TDataSet.RPDCY_TRow row in dsData.RPDCY_T.Rows ) //
doesn't execute anything - no rows
DiagnosticLog.Debug( row.TAG.ToString() + " " +
row.SRC_TAG.ToString()
+
" " + row.DST_TAG.ToString() );

So am I doing something wrong when referencing my Rows of my types DataSet
class?

You will find that you now have 2 tables in the dataset. Your
DataAdapter.Fill created a new table instead of filling the existing one.
This is an annoying "feature" of datasets, it's really easy to add a new
table using a DataAdapter. For typed datasets you almost never want to do
that.

use
daNew.Fill( dsData, "RPDCY_T" );
or
daNew.Fill( dsData, dsData.RPDCY_T.Rows);

instead.

David
 

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

Similar Threads


Top