Home All Groups Group Topic Archive Search About

Cannot access Columns and Rows of some Strong-Typed Dataset's DataTables

Author
9 Dec 2004 7:28 PM
Kyle
I am having a major issue with strongly typed datasets.  I have been
using the Server Explorer in VS.net 2003 to add tables from the
database into a DataSet.  I cannot access the rows or columns of some
of the DataTables.  What can I do to fix this, or why can I not do
this?  I cannot find any information on the topic.

Here is an example:
TypedDataSet ds = new TypedDataSet();

// fill tables

int id = ds.Customers[0].CustomerID;  <-- For some tables, this works
int id = ds.Orders*** <-- sometimes I cannot access [int] or columns

I cannot access anything like ds.Orders.OrderIDColumn.  They do not
show up in the IDE and I cannot build the project.  It is like they do
not exist.  Please help me fix this.  Thanks!

Kyle

Author
9 Dec 2004 9:06 PM
W.G. Ryan eMVP
When you say sometimes, does that mean taht sometimes you can as well?

I've seen something similar when you move a dataset in an existing assembly
to a new one with a different namespace, but if the lines are right next to
each other, that's weird.  You can try to regen the dataset using xsd.exe
which may fix it.  Another approach is to copy the XML definition inisde of
it, delete the dataaset, add a new one with the same name and paste the
definition in there.

Again make sure that the names are spelled correctly - no other syntax
errors and all taht good stuff but I'm guessing you've already done that.

BTW, if you use dataSet.Tables[TableIndex].Rows[RowIndex][ColumnIndex]; ---
does that work?  I know that's not what yuo are asking, but I'm curious to
see if those are actually available or not.

Show quote
"Kyle" <fis***@gmail.com> wrote in message
news:1102620501.289528.295020@f14g2000cwb.googlegroups.com...
> I am having a major issue with strongly typed datasets.  I have been
> using the Server Explorer in VS.net 2003 to add tables from the
> database into a DataSet.  I cannot access the rows or columns of some
> of the DataTables.  What can I do to fix this, or why can I not do
> this?  I cannot find any information on the topic.
>
> Here is an example:
> TypedDataSet ds = new TypedDataSet();
>
> // fill tables
>
> int id = ds.Customers[0].CustomerID;  <-- For some tables, this works
> int id = ds.Orders*** <-- sometimes I cannot access [int] or columns
>
> I cannot access anything like ds.Orders.OrderIDColumn.  They do not
> show up in the IDE and I cannot build the project.  It is like they do
> not exist.  Please help me fix this.  Thanks!
>
> Kyle
>
Author
9 Dec 2004 9:43 PM
Kyle
The two tables will be in the same DataSet, and come from the same
database.  I can access the various fields specific to that table for
one table, but not the other.  Oddly, I cannot access the row numbers
through ds.TableName[rownumber] at all for that "bad" table.  It is
almost as if it is an untyped dataset.

I can access the data through the untyped
ds.Tables["TableName"].Rows[RowNo]["ColumnName"].

But, my work wants them all typed.  So, it is not an option at this
point. :(  I have had this happen with two different datasets, and the
same tables.  The problem is 100% repeatable.  I don't know if the DB
makes a difference, but we use Pervasive.  Thanks for the help.

Kyle
Author
9 Dec 2004 10:59 PM
Sahil Malik
Kyle,

Check and see if your strongly typed dataset hasn't been defined as a plain
vanilla dataset in the block of code this happens in.

Also, does restarting the ide fix it? does restarting the pc fix it?

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik





Show quote
"Kyle" <fis***@gmail.com> wrote in message
news:1102628598.788775.290770@c13g2000cwb.googlegroups.com...
> The two tables will be in the same DataSet, and come from the same
> database.  I can access the various fields specific to that table for
> one table, but not the other.  Oddly, I cannot access the row numbers
> through ds.TableName[rownumber] at all for that "bad" table.  It is
> almost as if it is an untyped dataset.
>
> I can access the data through the untyped
> ds.Tables["TableName"].Rows[RowNo]["ColumnName"].
>
> But, my work wants them all typed.  So, it is not an option at this
> point. :(  I have had this happen with two different datasets, and the
> same tables.  The problem is 100% repeatable.  I don't know if the DB
> makes a difference, but we use Pervasive.  Thanks for the help.
>
> Kyle
>
Author
10 Dec 2004 2:29 PM
Kyle
According to the IDE and itellisense, it has been defined as
TypedDataSet.OrdersDataTable.

Restarting the IDE and restarting the PC does not fix it.

Something interesting, is that if I define a new row by:
TypedDataSet.OrdersRow row = ds.Orders.NewRow();

Then, I can access column data through (assuming a new row had data):
int orderid = (int) row.OrderID;
string address = (string)  row.Address1;

That is very odd.   I cannot access the existing rows though, only th e
new row if I define a new row.  Very odd.  What do you think it could
be?  Thanks.

Kyle
Author
9 Dec 2004 11:09 PM
W.G. Ryan eMVP
Ok, that helps out a lot.  Try rebuilding the dataset.  The back end has 0
bearing on this.  Typed datasets are funny beasts - if you move them from
project to project the namespace difference can give you headaches.  Delete
the current one and recreate it or regen it w/ xsd.exe.  That should do it
for you.

--
W.G. Ryan MVP (Windows Embedded)

TiBA Solutions
www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
Show quote
"Kyle" <fis***@gmail.com> wrote in message
news:1102628598.788775.290770@c13g2000cwb.googlegroups.com...
> The two tables will be in the same DataSet, and come from the same
> database.  I can access the various fields specific to that table for
> one table, but not the other.  Oddly, I cannot access the row numbers
> through ds.TableName[rownumber] at all for that "bad" table.  It is
> almost as if it is an untyped dataset.
>
> I can access the data through the untyped
> ds.Tables["TableName"].Rows[RowNo]["ColumnName"].
>
> But, my work wants them all typed.  So, it is not an option at this
> point. :(  I have had this happen with two different datasets, and the
> same tables.  The problem is 100% repeatable.  I don't know if the DB
> makes a difference, but we use Pervasive.  Thanks for the help.
>
> Kyle
>
Author
10 Dec 2004 3:02 PM
Kyle
I rebuilt the DataSet four ways:
1. Removed table, readded through server explorer.
2. Created new dataset and added through server explorer.
3. Created new project, and created a data adapter, and then generated
the dataset from that.
4. Regenerated the file with XSD.exe.

None of them worked.  The table is generated exactly the same way,
except in #3, where it is defined as "Table" instead of "Orders"  I
tried renaming that one in the XSD to "Orders" and the same problems
exist.

Kyle

AddThis Social Bookmark Button