Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Datagrid-How to get data from two tables

I am using VB2003. In datagrid How do i get data from two joined tabled. For example i want get data from transactiondetail and product master. It have join with the join key productcode. I want to display all fields from transaction details including the productcode and corresponding details from product master. That is, when we will enter the productcode, immediately it has to display the product details.

Plese help me in this.
[449 byte] By [siraj_nm] at [2007-11-11 10:26:57]
# 1 Re: Datagrid-How to get data from two tables
siraj_nm,

Here is a great resource for VS2003 datagrid questions:

http://www.syncfusion.com/FAQ/WindowsForms/Default.aspx#44

Kerry Moorman
kmoorman at 2007-11-11 20:47:40 >
# 2 Re: Datagrid-How to get data from two tables
Kmoorman

Thank you for giving me the link. I have visted. None of it helped me.

Thanks & Regards

Siraj
siraj_nm at 2007-11-11 20:48:51 >
# 3 Re: Datagrid-How to get data from two tables
Siraj: If I understand your question correctly, simply use a SQL query that joins the two tables, e.g.:

Dim cn as New SQLConnection(connectionString)
Dim dsProducts As New Dataset
Dim sdaProducts As New SqlDataAdapter( _
"SELECT ProductMaster.*, TransactionDetail.* " & _
"FROM ProductMaster INNER JOIN TransactionDetail " & _
"ON ProductMaster.ProductCode = TransactionDetail.ProductCode " & _
"WHERE ProductCode = 12345", cn)

sdaProducts.Fill(dsProducts, "Transactions")
DataGrid1.SetDataBinding(dsProducts, "Transactions")
Phil Weber at 2007-11-11 20:49:46 >
# 4 Re: Datagrid-How to get data from two tables
Phil Weber
Thank you for your reply. My question is not exactly you answered. Why dont i use this by relation. For example i have a common dataset named dsproduct and dstrdetail and i have established relation aswell. Why don't i join in gridcolumnstyle by its relation.

productid.mappingname = "productid" 'this field from trdetails
productname.mappingname = "product.productname" 'this field from product

Please help me in this.

Regards

Siraj

like this
siraj_nm at 2007-11-11 20:50:52 >
# 5 Re: Datagrid-How to get data from two tables
See if this helps: http://www.codeproject.com/vb/net/grid101.asp
Phil Weber at 2007-11-11 20:51:52 >