2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by amitj
0

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

if (con.State == ConnectionState.Closed)
            {
                con.Open();
            }
            DataColumn Col;
           
            Col = new DataColumn();
            Col.DataType = System.Type.GetType("System.String");
            Col.ColumnName = "S.No.";
            dt_medilist1.Columns.Add(Col);
            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;
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.