Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...