AD
Administrator
Syncfusion Team
October 16, 2002 06:04 AM UTC
I am not sure if this is what you want to do, but here is a link on how to take data from two tables and display it in a single grid.
I want to do sort of a database join of two tables. How can I use data from two DataTables in a single DataGrid?
http://www.syncfusion.com/faq/winforms/search/882.asp
AY
aydinturker
October 16, 2002 10:32 AM UTC
hi clay,
i mean;
Dim dtable1 As New DataTable()
Dim dtable2 As New DataTable()
OleDbDataAdapter1.Fill(dtable1)
dtable2.Columns.Add(dtable1.Columns(0))
DataGrid1.DataSource = dtable2
exception msg =Column 'Columnname' already belongs to another datatable
> I am not sure if this is what you want to do, but here is a link on how to take data from two tables and display it in a single grid.
>
> I want to do sort of a database join of two tables. How can I use data from two DataTables in a single DataGrid?
>
> http://www.syncfusion.com/faq/winforms/search/882.asp
>
AD
Administrator
Syncfusion Team
October 16, 2002 01:09 PM UTC
Is it your aim for all the data in column 0 of table 1 be available in column 0 of table 2?
Just adding a column does not populate the rows. If you want to try what your code suggests, you would have to add a New DataColumn to table2 with the same columnname and datatype as column0 from table 1. Then you would have to loop through all the rows in table one and add a new row to table2 for each row in table1. Below is some code (but I did not check the syntax...)
Dim dtable1 As New DataTable()
Dim dtable2 As New DataTable()
OleDbDataAdapter1.Fill(dtable1)
Dim dc as DataColumn = dtable1.Columns(0);
dtable2.Columns.Add(New DataColumn(dc.ColumnName, dc.DataType))
dim dr1, dr2 as DataRow
Foreach dr1 in dtable1.Rows
dr2 = dtable2.NewRow()
dr2(0) = dr1(0)
dtable2.Rows.Add(dr2)
next
AY
aydinturker
October 16, 2002 03:36 PM UTC
thanks clay,
it's ok.
you're my code hero.
> Is it your aim for all the data in column 0 of table 1 be available in column 0 of table 2?
>
> Just adding a column does not populate the rows. If you want to try what your code suggests, you would have to add a New DataColumn to table2 with the same columnname and datatype as column0 from table 1. Then you would have to loop through all the rows in table one and add a new row to table2 for each row in table1. Below is some code (but I did not check the syntax...)
>
>
> Dim dtable1 As New DataTable()
> Dim dtable2 As New DataTable()
> OleDbDataAdapter1.Fill(dtable1)
>
> Dim dc as DataColumn = dtable1.Columns(0);
>
> dtable2.Columns.Add(New DataColumn(dc.ColumnName, dc.DataType))
>
> dim dr1, dr2 as DataRow
>
> Foreach dr1 in dtable1.Rows
> dr2 = dtable2.NewRow()
> dr2(0) = dr1(0)
> dtable2.Rows.Add(dr2)
> next
>
>
>