datasets and datatables questions:)

J

Joe777

Hi all, I am new to this forum and .net in general so please be gentle
:)

I have a couple of questions regarding datasets, datarelations and
datatables and their overall functionality.


When you fill a dataset with 2 seperate queries does asp .net
automatically
put the tables into the datatables collection for you for later
reference or
do I have to declare a new datatable for each table I plan on adding
into my datarelation?


I only need to create new datatable objects when I want to loop
through it's rows, view constraints, primary keys, etc... ie: I
don't always need a datatable object when I am working with a
dataset?


Cheers, Joe
 
W

William Ryan eMVP

Joe777 said:
Hi all, I am new to this forum and .net in general so please be gentle
:)

I have a couple of questions regarding datasets, datarelations and
datatables and their overall functionality.


When you fill a dataset with 2 seperate queries does asp .net
automatically
put the tables into the datatables collection for you for later
reference or
do I have to declare a new datatable for each table I plan on adding
into my datarelation?

It may.

If you used DataAdapter.Fill(myDataSet, "FirstTable")
DataAdapter.Fill(myDataSet, "SecondTable")
then it will.
If you use batch sql statement it will too. However if you fill the same
tablename, it won't
Either way, if you don't use a strongly typed dataset, you'll need to add
the datarelations manually
http://www.knowdotnet.com/articles/datarelation.html
I only need to create new datatable objects when I want to loop
through it's rows, view constraints, primary keys, etc... ie: I
don't always need a datatable object when I am working with a
dataset?
Normally, you want to keep datasets alive as long as possible. Often you can
use DataSets and DataTables fairly interchangeable since you can reference
the table in the dataset or you can reference the table name outside of the
datatable depending on how you declared everything.

You do however worth with a datatable or group of datatables when you are
doing things. there's no such thing as iterating the rows of a datatable
(although you could iterate the tables since they are a collection)

A DataSet is a collection of 0 or more datatables, so if you are using one,
you are using datatables for the overwhelming majority of tasks. You may
reference it
Datasetname.Tables["TableNameOrIndex"]; or you may just use DataTableName
(if you declared an instance of a datatable) either way you're doing
essentially the same thing.

HTH,

Bill
 

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