|
-
Jul 10th, 2007, 11:37 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] DataTable vs DataSet
Hi all,
sorry if this is pretty basic but im a little confused about the releation between datasets and dataTables
If i have a dataset the info i fill it with would be the Datatables? I assume i can fill a dataset with more than one DataTable
if i need to manipulate the data i would do it from the datatable?
If i am just given a dataset how would i tell how many datatables are in it ( if the above statements are true)
Thanks
Robert
-
Jul 10th, 2007, 11:43 AM
#2
Re: DataTable vs DataSet
a dataset can contain zero or more datatables. A datatable can contain zero or more datarows. A datarow can contain zero or more datacolumns.
They all have a .Count property
But a datatable can exist outside a dataset. A dataset is most usefull if 1) you want to relate multiple datatables to each other (vis dataRelations) or if 2) you simply just want to have all your datatables in one spot rather than in multiple variables.
-tg
-
Jul 10th, 2007, 12:11 PM
#3
Re: DataTable vs DataSet
 Originally Posted by tg
a dataset can contain zero or more datatables...
No Sir, Dataset contains 1 DataTableCollection, which in turns contains zero or more Datatables, and so on.
That's why you have to specify the index of DataTable when accessing a table inside DataSet.
example.
Code:
DataSet ds = new DataSet();
string item;
item = ds.Tables["tablename"].Rows[rowindex][columnindex].ToString();
-
Jul 10th, 2007, 12:39 PM
#4
Re: DataTable vs DataSet
now you're just splitting hairs..... and it doesn't have to be an index (which insinuates a numeric value) it can also be a Key/TableName (as shown in your example).
-tg
-
Jul 10th, 2007, 12:43 PM
#5
Re: DataTable vs DataSet
Even I was not completely right 
-
Jul 10th, 2007, 05:18 PM
#6
Thread Starter
Fanatic Member
Re: DataTable vs DataSet
so if i am only useing one set of data that i dont need to releate to any other data i should just work in a datatable?
-
Jul 10th, 2007, 07:06 PM
#7
-
Jul 10th, 2007, 07:41 PM
#8
Re: DataTable vs DataSet
The other advantage of the DataSet class is that it inherits Component, which means it has design-time support. You can add a DataSet to a form in the designer but you cannot do the same with a DataTable. If you're not separating your data layer from your presentation layer then I'd suggest taking advantage of this fact so that you can set up data-binding at design time.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|