473,549 Members | 3,749 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.fieldnam e, fieldvalues.val ue 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 18238
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.Fi ll(dataSetName, "Fields");
dataAdapter2.Fi ll(dataSetName, "FieldValue s");
dataGrid1.DataS ource =- 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.Up date(dataSetNam e, "Fields");
dataAdapter2.Up date(dataSetNam e, "FieldValue s");
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 DataAdpaterConf iguration 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.goo gle.com...
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.fieldnam e, fieldvalues.val ue 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
2586
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 the column in the DataSet table consist of DateTime value. I also have two DateTimePicker (startDate and endDate) on my Windows form.
3
1191
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 it using datagrid. inC#.Net ..
3
2684
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 populate multiple webpages containing customer information. There isn't a one-to-one correlation between the stored procedure and a webpage. In other...
3
2076
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 databases, the data is ordered alphabetically but is grouped by database. Here is an example of what is happening to the data in the datgrid with the code...
2
6380
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
2906
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 have written the code using radio button for selecting single item.but we want to replace it with checkbox to select multiple items. the code...
3
1698
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, GetParentRows, GetChildRows. However, I don't see a good way to represent data from multiple dataset tables within a single datagrid (although I can think of...
0
1215
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 Titles, Authors & Prices, and update the prices. The code I'm using is below, but I get an exception, on binding the grid stating "A field or...
1
24346
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 SqlDataAdapter(strSQL, sqlConn) dSet = New DataSet()
0
7455
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7723
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7962
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7814
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6050
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5373
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5092
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3486
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.