Add a new Row in a datagridview which is binded to a datatable
Expand Post »
I fetch the data datafrom database in to a datatable and bind it to a datagridview.Now I want to edit the data shown in the datagridviewand also want to add new rows in dgv.The editing part is going ok but I m not able to add new rows in dgv.Also I want S.No. column to be autogenerated on new row...the coding is below
SqlDataAdapter adp1 = new SqlDataAdapter("Select Drugs,Schedule,Instructions,(DateTo)Till,Route,(Qty)Quantity,Comments from tblTreatment where Patient=111", con);
adp1.Fill(dt_medilist1);
int rows = dt_medilist1.Rows.Count;
for(int i = 0; i < rows; i++)
{
dt_medilist1.Rows[i]["S.No."] = i + 1;
}
dataGridView1.DataSource = dt_medilist1;
Last edited by Tekmaven; Jul 19th, 2008 at 2:30 pm. Reason: Code tags
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.