I've been trying to get the Datatable.clone method to work in my application and I am running out of ideas. Basically I have a dataset with a datatable, fully populated. I created another datatable and added it into the dataset. Cloned the 1st datatable
schema into the 2nd but when I run my program it fails. The 2nd DataTable doesn't have any columns in it, although it has 394 rows, which doesn't make sense. Here's a small snippit of code:
Sub ValidateEnrollments()
Dim tblErrorEnrollments As DataTable
tblErrorEnrollments = myDataSet.Tables("Enrollments").Clone
tblErrorEnrollments = myDataSet.Tables.Add("tblErrorEnrollments")
After setting breakpoints, I can see that tblErrorEnrollments has no columns, although a lot of rows, populated with the remainder of code. This is my first attempt at working with datasets/datatables in code behind. Any help would be much appreciated.
Well, I got this working although I am miss-understanding the interaction of the DataTable with the DataSet. I ended up having two DataTables, one inside the dataset with no schema and one outside the datatable also with no schema. By removing the 4th
line in my code above, the DataTable outside the Dataset started working...at least in terms of having a schema with data that could populate my Gridview.
RDMathews
Member
2 Points
4 Posts
Cloning a DataTable (only need the Schema)
Nov 11, 2012 03:30 AM|LINK
I've been trying to get the Datatable.clone method to work in my application and I am running out of ideas. Basically I have a dataset with a datatable, fully populated. I created another datatable and added it into the dataset. Cloned the 1st datatable schema into the 2nd but when I run my program it fails. The 2nd DataTable doesn't have any columns in it, although it has 394 rows, which doesn't make sense. Here's a small snippit of code:
Sub ValidateEnrollments() Dim tblErrorEnrollments As DataTable tblErrorEnrollments = myDataSet.Tables("Enrollments").Clone tblErrorEnrollments = myDataSet.Tables.Add("tblErrorEnrollments")After setting breakpoints, I can see that tblErrorEnrollments has no columns, although a lot of rows, populated with the remainder of code. This is my first attempt at working with datasets/datatables in code behind. Any help would be much appreciated.
RDMathews
Member
2 Points
4 Posts
Re: Cloning a DataTable (only need the Schema)
Nov 11, 2012 04:35 AM|LINK
Well, I got this working although I am miss-understanding the interaction of the DataTable with the DataSet. I ended up having two DataTables, one inside the dataset with no schema and one outside the datatable also with no schema. By removing the 4th line in my code above, the DataTable outside the Dataset started working...at least in terms of having a schema with data that could populate my Gridview.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: Cloning a DataTable (only need the Schema)
Nov 12, 2012 01:01 AM|LINK
Hello,
I come here to confirm whether your problem is solved or not. If solved, please mark as an answer so that I'll close your issue.
Reguards!