all groups > vb.net controls > january 2005 >
You're in the

vb.net controls

group:

Presenting 2 related datatable into a datagrid


Re: Presenting 2 related datatable into a datagrid Ken Tucker [MVP]
1/26/2005 5:49:53 AM
vb.net controls: Hi,

Add a datarelation to link 2 tables together or 2 data relation to
connect 3 tables. Here is a sample that uses the northwind database. I
added Imports System.Data.SqlClient at the top of the file. I have a
windows form with a datagrid on it. I placed this code in the form load
event.

Dim strConn As String

Dim conn As SqlConnection

Dim daCustomer As SqlDataAdapter

Dim daOrders As SqlDataAdapter

Dim daOrderDetails As SqlDataAdapter

Dim ds As DataSet

ds = New DataSet()

strConn = "Server = " + Environment.MachineName + "\VSdotNet;"

strConn += "Database = NorthWind;"

strConn += "Integrated Security = SSPI;"

conn = New SqlConnection(strConn)

daCustomer = New SqlDataAdapter("Select * from customers", conn)

daOrders = New SqlDataAdapter("Select * from orders", conn)

daOrderDetails = New SqlDataAdapter("Select * from [order details]", conn)

ds = New DataSet()

daCustomer.Fill(ds, "Customer")

daOrders.Fill(ds, "Orders")

daOrderDetails.Fill(ds, "OrderDetails")

ds.Relations.Add("CustomerOrder",
ds.Tables("Customer").Columns("CustomerID"), _

ds.Tables("Orders").Columns("CustomerID"))

ds.Relations.Add("Order-Details", ds.Tables("Orders").Columns("OrderID"), _

ds.Tables("OrderDetails").Columns("OrderID"))

DataGrid1.DataSource = ds.Tables("Customer")


http://www.onteorasoftware.com/downloads/multigrids.zip


Ken

-----------------

[quoted text, click to view]
Hi Everyone


I have a DataSet with two datatables
Say One is Customer and one is CodeTable_Country

Customer Table contains a field called CustomerID, CustomerName, CountryID,
like
[Customer]
-----------------
CustomerID
CustomerName
CountryID


And the CodeTable_Country Table contains a CountryID and
CountryDescriptions, like
[CodeTable_Country]
---------------------------
CountryID
CountryDescriptions


I have set the datarealtion between customer and codetable_country using
countryID, but how can i display them in datagrid so that
[DataGrid]
-----------------------
CustomerName
CountryDescriptions


Thx and regards,
Norton


Presenting 2 related datatable into a datagrid norton
1/26/2005 6:23:17 PM
Hi Everyone


I have a DataSet with two datatables
Say One is Customer and one is CodeTable_Country

Customer Table contains a field called CustomerID, CustomerName, CountryID,
like
[Customer]
-----------------
CustomerID
CustomerName
CountryID


And the CodeTable_Country Table contains a CountryID and
CountryDescriptions, like
[CodeTable_Country]
---------------------------
CountryID
CountryDescriptions


I have set the datarealtion between customer and codetable_country using
countryID, but how can i display them in datagrid so that
[DataGrid]
-----------------------
CustomerName
CountryDescriptions


Thx and regards,
Norton

Re: Presenting 2 related datatable into a datagrid Ken Tucker [MVP]
1/27/2005 6:46:14 AM
Hi,

http://support.microsoft.com/default.aspx?scid=kb;EN-US;319082

Ken
-------------
[quoted text, click to view]
Ken

Thx for your help. but the scenario of this case has some difference with
mine. Sorry for misleading

in my Case, the relationship between customer and [codetable_country] is one
to Many relationship. and I would like to merge it into a flat datagrid like

[DataGrid]
CustomerID
CustomerName
CountryDescriptions

(and the datagrid won't have a "+" signal for showing that relationship as
all information is presented in the that flat datagrid )

Thx for your kindest help again !


Regards,
Norton


"Ken Tucker [MVP]" <vb2ae@bellsouth.net> ¼¶¼g©ó¶l¥ó·s»D
:eWheHT5AFHA.1204@TK2MSFTNGP10.phx.gbl...
[quoted text, click to view]


Re: Presenting 2 related datatable into a datagrid norton
1/27/2005 9:35:16 AM
Ken

Thx for your help. but the scenario of this case has some difference with
mine. Sorry for misleading

in my Case, the relationship between customer and [codetable_country] is one
to Many relationship. and I would like to merge it into a flat datagrid like

[DataGrid]
CustomerID
CustomerName
CountryDescriptions

(and the datagrid won't have a "+" signal for showing that relationship as
all information is presented in the that flat datagrid )

Thx for your kindest help again !


Regards,
Norton


"Ken Tucker [MVP]" <vb2ae@bellsouth.net> ¼¶¼g©ó¶l¥ó·s»D
:eWheHT5AFHA.1204@TK2MSFTNGP10.phx.gbl...
[quoted text, click to view]

Re: Presenting 2 related datatable into a datagrid norton
1/28/2005 12:53:39 AM
Yeah ~
thatz exactly want i want~
thanks Ken

Regards,
Norton


"norton" <nortonwong@hotmail.com> ¼¶¼g©ó¶l¥ó·s»D
:#KM3OE5AFHA.2820@tk2msftngp13.phx.gbl...
[quoted text, click to view]

AddThis Social Bookmark Button