How to create a new datarow without overwriting exitsting row?

  • Thread starter Thread starter Eddie B.
  • Start date Start date
E

Eddie B.

I was wondering if anyone knew how to create a new datarow without
overwriting exitsting row?
 
If you're talking about DataTable, then it has a .NewRow() method.

DataRow row = dt.NewRow();
row["Column1"] = someValue1;
row["Column2"] = someValue2;
dt.Add(row);

Don't forget the last statement.

-Oleg.
 
this is what I am doing. Toward the bottom (about 8 uncommented lines from
bottom) where DataRow first appears is where my trouble starts.
//Create DataSet

DataSet ds = new DataSet();

//Create DataTable

DataTable dt = new DataTable("Meds");

//Add DataTable to DataSet

ds.Tables.Add(dt);

//Add Columns to DataTable

DataColumn dc = new DataColumn("Drug");

ds.Tables["Meds"].Columns.Add(dc);

DataColumn dc2 = new DataColumn("Dose");

ds.Tables["Meds"].Columns.Add(dc2);

DataColumn dc3 = new DataColumn("Form");

ds.Tables["Meds"].Columns.Add(dc3);

DataColumn dc4 = new DataColumn("Route");

ds.Tables["Meds"].Columns.Add(dc4);

DataColumn dc5 = new DataColumn("Frequency");

ds.Tables["Meds"].Columns.Add(dc5);

DataRow tr = dt.NewRow();

tr["Drug"] = this.textBox11.Text;

tr["Dose"] = this.textBox12.Text;

tr["Form"] = this.textBox13.Text;

tr["Route"] = this.textBox14.Text;

tr["Frequency"] = this.textBox15.Text;


//Add rows to data table

dt.Rows.Add(tr);


//Display in dataGrid

this.dataGrid3.DataSource = dt;
 
I am doing exactly what you are saying but it does not seem to add a new
row, it only overwrites the existing row.

Oleg Ogurok said:
If you're talking about DataTable, then it has a .NewRow() method.

DataRow row = dt.NewRow();
row["Column1"] = someValue1;
row["Column2"] = someValue2;
dt.Add(row);

Don't forget the last statement.

-Oleg.

Eddie B. said:
I was wondering if anyone knew how to create a new datarow without
overwriting exitsting row?
 
Back
Top