HighTechTalks DotNet Forums  

traversing strongly typed DataSet

Dotnet Framework (ADO.net) microsoft.public.dotnet.framework.adonet


Discuss traversing strongly typed DataSet in the Dotnet Framework (ADO.net) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Corey Wirun
 
Posts: n/a

Default traversing strongly typed DataSet - 06-09-2004 , 10:51 AM






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.



Reply With Quote
  #2  
Old   
David Browne
 
Posts: n/a

Default Re: traversing strongly typed DataSet - 06-09-2004 , 11:52 AM







"Corey Wirun" <corey.wirun (AT) nospam (DOT) ca> wrote

Quote:
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




Reply With Quote
  #3  
Old   
Corey Wirun
 
Posts: n/a

Default Re: traversing strongly typed DataSet - 06-09-2004 , 12:21 PM



Once more, the Grasshopper is humbled by the Master.

Thanks David.
Corey.

"David Browne" <davidbaxterbrowne no potted meat (AT) hotmail (DOT) com> wrote in
message news:e3FVxIkTEHA.3480 (AT) TK2MSFTNGP11 (DOT) phx.gbl...
Quote:
"Corey Wirun" <corey.wirun (AT) nospam (DOT) ca> wrote in message
news:7mGxc.1963$cS.1659 (AT) edtnps89 (DOT) ..
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





Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.