kasdoffe
Well-known member
- Joined
- Aug 27, 2003
- Messages
- 57
Help me with this sample code:
When this is all finished, row count is still 0. How do I merge rows into a dataset without actually adding them to a table and merging the table into the dataset?
Using a performance profiler software, Ive found that looping and adding 5000 rows to a table takes quite a while to do.
I assumed, Hey, im sure theres a way to add a bunch of rows at once, wonder how long that takes?
I was hoping there was something like DataTable.AddRange, but you can only add 1 row at a time to a table.
Any ideas? Please tell me whats wrong with my code though...
Code:
// create dataset and datatable
DataSet myDataSet = new DataSet("myDataSet");
DataTable myDataTable = new DataTable("myDataTable");
// add column to table
myDataTable.Columns.Add(new DataColumn("c1",typeof(int)));
// create datarow array of 3 rows
DataRow [] dra = new DataRow[3];
// setup row 1
dra[0] = myDataTable.NewRow();
dra[0][0]=0;
// setup row 2
dra[1] = myDataTable.NewRow();
dra[1][0]=1;
// setup row 3
dra[2] = myDataTable.NewRow();
dra[2][0]=2;
// merge rows into dataset
myDataSet.Merge(dra,true,MissingSchemaAction.Add);
// accept changes
myDataSet.AcceptChanges();
// write row count
System.Diagnostics.Debug.WriteLine(myDataSet.Tables[0].Rows.Count.ToString());
When this is all finished, row count is still 0. How do I merge rows into a dataset without actually adding them to a table and merging the table into the dataset?
Using a performance profiler software, Ive found that looping and adding 5000 rows to a table takes quite a while to do.
I assumed, Hey, im sure theres a way to add a bunch of rows at once, wonder how long that takes?
I was hoping there was something like DataTable.AddRange, but you can only add 1 row at a time to a table.
Any ideas? Please tell me whats wrong with my code though...