473,386 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Populate DataGrid from a dataset w/multiple tables?

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
1 18226
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Soul | last post by:
*** I am not sure this question belong to *.languages.csharp or *.framework.windowsdorms.databinding, so I post to both *** Hi, Currently I have a DataGrid which bind to a DataSet. One of...
3
by: Karunakararao | last post by:
Hi All i have 40,000 records. populate the total records in Datagrid . it's taken time I need to populate the first 2000 records After the need to populate next 2000 records. how can i do...
3
by: Yul | last post by:
Hi, We are in the process of designing an ASP.NET app, where a user will enter some 'Customer ID' to be queried in the database. If the ID is valid, several stored procedures will be called to...
3
by: crjunk | last post by:
I have 4 different databases that I'm having to pull data from in order to populate a datagrid. I am able to do this, but my problem is that because I'm pulling the data from 4 different...
2
by: CSL | last post by:
I am using the DataGrid in a Windows Application, how can I adjust the widths of each column individually.
1
by: sneha123 | last post by:
There will be some 20 questions and for each question there will be 4 choices.what i want to do is to select multiple answers by clicking the checkbox. i m using asp.net,vb.net pls help me we...
3
by: Aaron | last post by:
Hi, It is possible to establish relationships between tables within a dataset and this allows some useful features. For example, given a row from a table you can use GetParentRow,...
0
by: bh | last post by:
Using the pubs database, for testing, and example, I'm trying to bind a datagrid that draws data from multiple tables to use for updating multiple rows at once. For my example, I want to display...
1
by: rn5a | last post by:
I was using a DataView to bind records from a DB table to a DataGrid using the following code: Dim sqlDapter As SqlDataAdapter Dim dSet As DataSet Dim dView As DataView sqlDapter = New...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.