Using Strongly Typed Datasets

C

ctilly

I am interested in using strong typed datasets, but I am having some
difficulty with some things and was hoping for a little clarification.

I am using VS 2005 (.net 2) and I start off by creating a Dataset to my

project called MyDataset.xsd.

In my Dataset I added a TableAdapter called Products, which resulted in

the creation of a TableAdapter named ProductsTableAdapter and a
DataTable named Products.

So far so good.

What I thought strongly typed datasets would allow me to do is write
code like this....

MyDataset mds = new MyDataset();
mds.ProductsTableAdapter.Fill(mds.Products);

or even better yet...

MyDataset mds = new MyDataset();
mds.Products.GetData();
Textbox1.Text = mds.Products.Rows[1]["ProductName"];

And if I add another query to the DataAdapter such as
"FillByProductID,GetDataByProductID (@ProductID)" then I could say
something like...

MyDataset mds = new MyDataset();
mds.Products.GetDataByProductID(someInt);
Textbox1.Text = mds.Products.Rows[1]["ProductName"];

Now I know the methods I am invoking are TableAdapter methods and not
DataTable methods. However, what the DataSet Designer seems to be
doing is "binding" the TableAdapter to the DataTable. It seems like
that coupling of the TableAdapter with the DataTable should abstract
the TableAdapter and make it so you can get at the data via the
DataTable directly without having to also worry about the TableAdapter.


Instead I find I have to use very cumbersome code, and not at all
intuitive, to get at my data in the MyDataset.

using MyDatasetTableAdapters; // <== THIS TOOK A WHILE TO FIGURE OUT
<snip>
ProductsTableAdapter pta = new ProductsTableAdapter();
DataTable mydt = pta.GetData();
Textbox1.Text = mydt.Rows[1]["ProductName"].ToString(); // <==
STRONGLY TYPED???

So what am I doing wrong? Is there a way to do what I want to do and I

am just going about it all wrong? Or are Visual Studio Datasets just a

waste of time? Because the data doesn't seem strongly typed if I have
to access via the TableAdapter. What am I missing here?

Regards.
 
D

David Browne

I am interested in using strong typed datasets, but I am having some
difficulty with some things and was hoping for a little clarification.

I am using VS 2005 (.net 2) and I start off by creating a Dataset to my

project called MyDataset.xsd.

In my Dataset I added a TableAdapter called Products, which resulted in

the creation of a TableAdapter named ProductsTableAdapter and a
DataTable named Products.

So far so good.

What I thought strongly typed datasets would allow me to do is write
code like this....

MyDataset mds = new MyDataset();
mds.ProductsTableAdapter.Fill(mds.Products);

or even better yet...

MyDataset mds = new MyDataset();
mds.Products.GetData();
Textbox1.Text = mds.Products.Rows[1]["ProductName"];

And if I add another query to the DataAdapter such as
"FillByProductID,GetDataByProductID (@ProductID)" then I could say
something like...

MyDataset mds = new MyDataset();
mds.Products.GetDataByProductID(someInt);
Textbox1.Text = mds.Products.Rows[1]["ProductName"];

Now I know the methods I am invoking are TableAdapter methods and not
DataTable methods. However, what the DataSet Designer seems to be
doing is "binding" the TableAdapter to the DataTable. It seems like
that coupling of the TableAdapter with the DataTable should abstract
the TableAdapter and make it so you can get at the data via the
DataTable directly without having to also worry about the TableAdapter.


Instead I find I have to use very cumbersome code, and not at all
intuitive, to get at my data in the MyDataset.

using MyDatasetTableAdapters; // <== THIS TOOK A WHILE TO FIGURE OUT
<snip>
ProductsTableAdapter pta = new ProductsTableAdapter();
DataTable mydt = pta.GetData();
Textbox1.Text = mydt.Rows[1]["ProductName"].ToString(); // <==
STRONGLY TYPED???

So what am I doing wrong? Is there a way to do what I want to do and I

am just going about it all wrong? Or are Visual Studio Datasets just a

waste of time? Because the data doesn't seem strongly typed if I have
to access via the TableAdapter. What am I missing here?

The division is intentional because the DataSet and DataTable might be used
much more widely than the TableAdapters, and have different visibility. If
you want some convenience methods on the DataSet or DataTable, they are
implemented as partial classes, and you can add custom methods that access
the TableAdapters.

David
 
C

Cor Ligthert [MVP]

CTilly,

Be aware that ASPNET and Winforms work and create completely different
styles of strongly typed datasets in Net 2.0. This beneath is about Winforms

In Net 2.0 the handling is more about datatables, a wish often told in past
(not by me).

However by using the DataSource you are able to put those in a dataset.
This simple procedure gives you a great sample of that.

http://www.vb-tips.com/dbpages.aspx?ID=1139f14a-c236-4ad7-8882-b1ed16424252

About your textbox, setting a text to a textbox is not as simple in Net as
binding the table to the textbox and than use the columname (In this sample
is for simplicity of the sample used a non typed dataset).

http://www.vb-tips.com/dbpages.aspx?ID=c4832a2a-2b95-4ded-93d9-4deb7fa4a0b8

I hope this helps,

Cor




I am interested in using strong typed datasets, but I am having some
difficulty with some things and was hoping for a little clarification.

I am using VS 2005 (.net 2) and I start off by creating a Dataset to my

project called MyDataset.xsd.

In my Dataset I added a TableAdapter called Products, which resulted in

the creation of a TableAdapter named ProductsTableAdapter and a
DataTable named Products.

So far so good.

What I thought strongly typed datasets would allow me to do is write
code like this....

MyDataset mds = new MyDataset();
mds.ProductsTableAdapter.Fill(mds.Products);

or even better yet...

MyDataset mds = new MyDataset();
mds.Products.GetData();
Textbox1.Text = mds.Products.Rows[1]["ProductName"];

And if I add another query to the DataAdapter such as
"FillByProductID,GetDataByProductID (@ProductID)" then I could say
something like...

MyDataset mds = new MyDataset();
mds.Products.GetDataByProductID(someInt);
Textbox1.Text = mds.Products.Rows[1]["ProductName"];

Now I know the methods I am invoking are TableAdapter methods and not
DataTable methods. However, what the DataSet Designer seems to be
doing is "binding" the TableAdapter to the DataTable. It seems like
that coupling of the TableAdapter with the DataTable should abstract
the TableAdapter and make it so you can get at the data via the
DataTable directly without having to also worry about the TableAdapter.


Instead I find I have to use very cumbersome code, and not at all
intuitive, to get at my data in the MyDataset.

using MyDatasetTableAdapters; // <== THIS TOOK A WHILE TO FIGURE OUT
<snip>
ProductsTableAdapter pta = new ProductsTableAdapter();
DataTable mydt = pta.GetData();
Textbox1.Text = mydt.Rows[1]["ProductName"].ToString(); // <==
STRONGLY TYPED???

So what am I doing wrong? Is there a way to do what I want to do and I

am just going about it all wrong? Or are Visual Studio Datasets just a

waste of time? Because the data doesn't seem strongly typed if I have
to access via the TableAdapter. What am I missing here?

Regards.
 
C

ctilly

Cor, thank you for your response. I am very interested in checking out
the links you provided, but the vb-tips.com site seems to be having
some problems since I can't seem to access it. Once the site comes up
I will check out what these articles have to say.

Again, thank you for your resonse.

Chuck

CTilly,

Be aware that ASPNET and Winforms work and create completely different
styles of strongly typed datasets in Net 2.0. This beneath is about Winforms

In Net 2.0 the handling is more about datatables, a wish often told in past
(not by me).

However by using the DataSource you are able to put those in a dataset.
This simple procedure gives you a great sample of that.

http://www.vb-tips.com/dbpages.aspx?ID=1139f14a-c236-4ad7-8882-b1ed16424252

About your textbox, setting a text to a textbox is not as simple in Net as
binding the table to the textbox and than use the columname (In this sample
is for simplicity of the sample used a non typed dataset).

http://www.vb-tips.com/dbpages.aspx?ID=c4832a2a-2b95-4ded-93d9-4deb7fa4a0b8

I hope this helps,

Cor




I am interested in using strong typed datasets, but I am having some
difficulty with some things and was hoping for a little clarification.

I am using VS 2005 (.net 2) and I start off by creating a Dataset to my

project called MyDataset.xsd.

In my Dataset I added a TableAdapter called Products, which resulted in

the creation of a TableAdapter named ProductsTableAdapter and a
DataTable named Products.

So far so good.

What I thought strongly typed datasets would allow me to do is write
code like this....

MyDataset mds = new MyDataset();
mds.ProductsTableAdapter.Fill(mds.Products);

or even better yet...

MyDataset mds = new MyDataset();
mds.Products.GetData();
Textbox1.Text = mds.Products.Rows[1]["ProductName"];

And if I add another query to the DataAdapter such as
"FillByProductID,GetDataByProductID (@ProductID)" then I could say
something like...

MyDataset mds = new MyDataset();
mds.Products.GetDataByProductID(someInt);
Textbox1.Text = mds.Products.Rows[1]["ProductName"];

Now I know the methods I am invoking are TableAdapter methods and not
DataTable methods. However, what the DataSet Designer seems to be
doing is "binding" the TableAdapter to the DataTable. It seems like
that coupling of the TableAdapter with the DataTable should abstract
the TableAdapter and make it so you can get at the data via the
DataTable directly without having to also worry about the TableAdapter.


Instead I find I have to use very cumbersome code, and not at all
intuitive, to get at my data in the MyDataset.

using MyDatasetTableAdapters; // <== THIS TOOK A WHILE TO FIGURE OUT
<snip>
ProductsTableAdapter pta = new ProductsTableAdapter();
DataTable mydt = pta.GetData();
Textbox1.Text = mydt.Rows[1]["ProductName"].ToString(); // <==
STRONGLY TYPED???

So what am I doing wrong? Is there a way to do what I want to do and I

am just going about it all wrong? Or are Visual Studio Datasets just a

waste of time? Because the data doesn't seem strongly typed if I have
to access via the TableAdapter. What am I missing here?

Regards.
 

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