We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

how can i add a datacolumn from another datatable

how can i add a datacolumn to mydatatable from another datatable

4 Replies

AD Administrator Syncfusion Team October 16, 2002 01:04 AM

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 05:32 AM

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 08:09 AM

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 10:36 AM

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 > > >

Loader.
Live Chat Icon For mobile
Up arrow icon