Typed dataset and databinding

A

Alienka

I have a problem with a typed dataset.

First I wrote a simple program that fetched one table from SQL Server
2000 to an UNTYPED dataset. Let's say, the table was called Table.
1. I added an untyped dataset in designer
2. I added a table to the dataset, called it Table
3. I added columns to Table in designer, so that they exactly matched
those in database
4. I added a datagrid to the form and set Table as source
5. Finally, I added some textboxes to the form and set bindings for
them to columns of Table, everything in designer

I filled the dataset using dataadapter and everything worked very well:
when I changed current row in datagrid, textboxes changed their values
to those from the current row.

And then I wrote another program. I created a TYPED dataset (from an
xsd file) that exactly matched the previous one (columns, types,
constraints etc). The only difference was it was typed (so inherited
after a dataset) and I no longer needed to type in columns manually.
1. I added the typed dataset in designer
2. I didn't have to add any tables to it, it already had Table with all
the necessary columns
3. I added a datagrid to the form and set typedDataSet.Table as source
5. Finally, I added some textboxes to the form and set bindings for
them to columns of typedDataSet.Table, everything in designer

And now, that's the point. It didn't work at all. I filled the dataset
with datadapter. When I changed current row in datagrid, values in
textboxes didn't refresh, as if textboxes were bound to the first row
in Table forever.

My question is: what did I do wrong? I guess typed dataset inherits ALL
benefits of an untyped one, so why binding works with an untyped
dataset, but stops working whenever I change the untyped dataset to
it's strongly typed equivalent? It's not the only program where I have
this problem. I encounter this problem in every project where I use a
typed dataset. Please help, I keep looking at the code but I can't see
anything "suspicious". And I keep looking for a solution in Google, but
can't find anything that could help me.

Thak you in advance!
 
B

Bart Mermuys

Hi,

Alienka said:
I have a problem with a typed dataset.

First I wrote a simple program that fetched one table from SQL Server
2000 to an UNTYPED dataset. Let's say, the table was called Table.
1. I added an untyped dataset in designer
2. I added a table to the dataset, called it Table
3. I added columns to Table in designer, so that they exactly matched
those in database
4. I added a datagrid to the form and set Table as source
5. Finally, I added some textboxes to the form and set bindings for
them to columns of Table, everything in designer

When using an Untyped DataSet in the designer then you can bind the Table
directly to the Texbox and to the grid too. No problem so far.
I filled the dataset using dataadapter and everything worked very well:
when I changed current row in datagrid, textboxes changed their values
to those from the current row.

And then I wrote another program. I created a TYPED dataset (from an
xsd file) that exactly matched the previous one (columns, types,
constraints etc). The only difference was it was typed (so inherited
after a dataset) and I no longer needed to type in columns manually.
1. I added the typed dataset in designer
2. I didn't have to add any tables to it, it already had Table with all
the necessary columns
3. I added a datagrid to the form and set typedDataSet.Table as source
5. Finally, I added some textboxes to the form and set bindings for
them to columns of typedDataSet.Table, everything in designer

When using Typed DataSets in the designer, you can *not* bind the Textbox
directly to the Table, it always goes through the typedDataset but you *can*
bind the DataGrid directly to Table and this causes independent navigating.

So if you are using the designer with Typed DataSet's, then the
DataSource of TextBox can only be typedDataSet (Table and Field are always
in DataMember)
DataSource of DataGrid can be typedDataSet or typedDataSet.Table

Now, if you want dependent navigating then it is important that the
DataSource's are the same. Don't set the DataGrid's DataSource property to
typedDataSet.Table but set it to typedDataSet instead. And then use its
DataMember property to specify a Table.



HTH,
Greetings
 

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

Top