Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display data from multiple tables in dataset

Status
Not open for further replies.

mk97

MIS
Oct 16, 2003
3
US
I am having problems with setting up a dataset and adapters.
I want to display data from 2 tables "Person" and "PersonContact"
for a particular person selected on a windows form.
By using parameterized query, how do I set adapters and dataset to accomplish this?

Currently, I have followings:
2 Tables "Person" and "PersonContact" that have relationship in a dataset "dsPersonFolder"

DataAdapter
"daPerson" .... "SELECT PersonID, FName FROM Person WHERE PersonID=?"

"daPersonContact" ...."SELECT PersonID, Street, City FROM PersonContact WHERE PersonID=?"

in VB.Net code,
Dim ID as Interger
...get a value of ID...
daPerson.SelectCommand.Parameters(0).Value = ID
daPersonContact.SelectedCommand.Parameters(0).Value = ID
daPerson.fill(dsPersonFolder.Person)
daPersonContact.fill(dsPersonFolder.PersonContact)

Does this make sense or I'm doing all wrong?
When do I use getchildrows method to get a realted data from its parent?
My way doesn't seem there is a relationship between tables when I call 2 datarows separately.

Do I even need to relate two tabels by saying
"SELECT P.PersonID, P.FName, PC.Street, PC.City
FROM Person P, PersonContact PC
WHERE P.PersonID=PC.PerosnID"

As you can tell, I am totally confused with dataset in ADO.net.
Please help me!!!

By the way, I am using MS Access for my database.
 
Hi,

Its not clear how you want to present the data to the user. Do you want the user to select a person (combobox?) and then show the ContactsPersons in the grid, show everything in one table in the grid or maybe relate the 2 tables to each other in the grid...
Here is how you can do the last:
-----------------------------------------------
Dim DA1 As New SqlDataAdapter("SELECT CustomerID, CompanyName, ContactName FROM Customers", Conn)
DA1.Fill(DS, "Customers")
Dim DA2 As New SqlDataAdapter("SELECT OrderID, CustomerID, OrderDate FROM orders", Conn)
DA2.Fill(DS, "Orders")
Dim DR As New DataRelation("FK_orders_customers", DS.Tables("Customers").Columns("CustomerID"), DS.Tables("Orders").Columns("CustomerID"))
DR.Nested = True
DS.Relations.Add(DR)

DS.Tables("Customers").Columns("CustomerID").ColumnMapping = MappingType.Hidden
DS.Tables("Orders").Columns("CustomerID").ColumnMapping = MappingType.Hidden

DataGrid1.DataSource = DS
----------------------------------------------------------

Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top