| | |
Add a new Row in a datagridview which is binded to a datatable
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2008
Posts: 2
Reputation:
Solved Threads: 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
C# Syntax (Toggle Plain Text)
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;
Last edited by Tekmaven; Jul 19th, 2008 at 2:30 pm. Reason: Code tags
•
•
Join Date: Aug 2008
Posts: 1,735
Reputation:
Solved Threads: 186
Did you enable adding records in your datagridview, and if you're manually adding them have you tried adding them to the datasource?
Did I just hear "You gotta help us, Doc. We've tried nothin' and we're all out of ideas" ? Is this you? Dont let this be you! I will put in as much effort as you seem to.
![]() |
Other Threads in the C# Forum
- Previous Thread: about streaming video file
- Next Thread: Reflection
| Thread Tools | Search this Thread |
.net access ado.net algorithm array association barchart bitmap box broadcast button buttons c# check checkbox client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing editing enabled encryption enum event excel file files form format forms function gdi+ httpwebrequest image index input install java label list listbox listener load mandelbrot math mouseclick mysql operator path photoshop picturebox pixelinversion post print programming radians regex remote remoting resolved. richtextbox saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer update user usercontrol validation view visualstudio webbrowser windows winforms wpf xml






