kasdoffe Posted October 13, 2005 Posted October 13, 2005 Help me with this sample 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()); [/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, I've found that looping and adding 5000 rows to a table takes quite a while to do. I assumed, 'Hey, i'm sure there's 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 what's wrong with my code though... Quote
kasdoffe Posted October 14, 2005 Author Posted October 14, 2005 bump? Any help at all? To test it, just use the exact code I'm using on a button click or something. It's screwy! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.