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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

how can i add a datacolumn from another datatable

Thread ID:

Created:

Updated:

Platform:

Replies:

1308 Oct 15,2002 02:02 PM UTC Oct 16,2002 03:36 PM UTC Windows Forms 4
loading
Tags: FAQ
aydinturker
Asked On October 15, 2002 02:02 PM UTC

how can i add a datacolumn to mydatatable from another datatable

Administrator [Syncfusion]
Replied On 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

aydinturker
Replied On 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 >

Administrator [Syncfusion]
Replied On 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

aydinturker
Replied On 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 > > >

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;