By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,126 Members | 1,210 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,126 IT Pros & Developers. It's quick & easy.

Populate DataGrid from a dataset w/multiple tables?

P: n/a
I have a dataset containing 2 tables. I need to fill a datagrid using
data from both of these.

If I could create a SQL Statement to fill the datagrid, it would look
like this:

SELECT fields.fieldname, fieldvalues.value FROM fields, fieldvalues
I am having trouble finding documentation explaining how to populate
my datagrid using MULTIPLE tables like this. I'm willing to bet this
is just a few lines of code--does anyone have an example?

Thanks,
Brian
Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I think you may want to switch tacks on this and go a totally different
direction. Create two dataadapters, one for fields, and one for
fieldvalues. Use one dataset and fill two different tables:

dataAdapter1.Fill(dataSetName, "Fields");
dataAdapter2.Fill(dataSetName, "FieldValues");
dataGrid1.DataSource =- dataSetName;
Now you can use the following to add a DataRelation:
http://www.knowdotnet.com/articles/datarelation.html. At this point you can
bind the grid to the dataset (if need be, manipulate the displaymember and
valuemember properties) and you'll see a + sign on the parent rows. When you
expand it the child rows will appear right underneath it slightly indented.

To upudate the rows, just use

dataAdapter1.Update(dataSetName, "Fields");
dataAdapter2.Update(dataSetName, "FieldValues");
making sure to update the parent table first so no integrity constraints get
violated. You can get a whole lot fancier with validation rules if you want
client side and you can (and may want to) use a StronglyTyped DataSet which
defines the Relations already.

Using Joins is not advised b/c 1) you pull over redundant data which is
wasteful in every regard 2) You won't be able to use a CommandBuilder or
the DataAdpaterConfiguration wizard to build the commands for you 3) Writing
your own logic will be somewhere between a total pain in the a55 and
impossible.

Use the datarelation and life will be simple - other than defining the
relation which takes 3 lines of code at most (and can be done on one),
that's all the code for the crux of your problem. HTH,

Bill

BTW, I have a bunch of other stuff on advanced filtering and sorting on the
data access section of www.knowdotnet.com
--
"Brian" <br*********@ky.gov> wrote in message
news:63**************************@posting.google.c om...
I have a dataset containing 2 tables. I need to fill a datagrid using
data from both of these.

If I could create a SQL Statement to fill the datagrid, it would look
like this:

SELECT fields.fieldname, fieldvalues.value FROM fields, fieldvalues
I am having trouble finding documentation explaining how to populate
my datagrid using MULTIPLE tables like this. I'm willing to bet this
is just a few lines of code--does anyone have an example?

Thanks,
Brian


W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
http://www.devbuzz.com/content/zinc_...center_pg1.asp
Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.