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.
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.