E
Eddie B.
I am trying to create a new row with the values from textboxes. When I
create the first row it works fine but when I click the button to create
another row it only overwrites the existing row. 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;
create the first row it works fine but when I click the button to create
another row it only overwrites the existing row. 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;