Ive been through all the help files but i can't seem to find what i'm looking for. I need to know how to add a new table to the dataset during run time. If anyone could help me that would be great.
Printable View
Ive been through all the help files but i can't seem to find what i'm looking for. I need to know how to add a new table to the dataset during run time. If anyone could help me that would be great.
I'm not at my dev machine, but all you need to do is create an instance of the data table class and add it to the dataset's table collection.
:rolleyes:
Dim myTable as DataTable
myDataset.Tables.Add(myTable)
Didn't mean to repeat you Lethal, It seems we were answering the same time.
Lunatic,
Don't forget you need to call the object's constructor to create an instance. ;)
Code:Dim myTable as New DataTable()
Oh Sure, Thanks:)
thanks everyone for your help, your advice help but the only problem now is that the new table that is created dose not have the same colums as my first original table. Can you help ?
Try the Clone() method:
Code:using System;
using System.Data;
class DataExample {
static void Main() {
DataTable dt = new DataTable("MyDataTable");
dt.Columns.Add(new DataColumn("Id"));
DataTable clone = dt.Clone();
foreach(DataColumn c in clone.Columns) {
Console.WriteLine("Column Name: {0}", c.ColumnName);
}
}
}