The text of this article is not in this database — only its details are. Read it on the old site: Insert, Update and Delete Records in a C# DataGridView
104 Comments
Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment.

Udochukwu John AnyanwuPosted Oct 9, 2024, 11:39 AM
Please can you reach you via email..
JimanshPosted May 14, 2023, 11:05 AM
Thanks alot
Mark Neil AbianPosted Feb 2, 2022, 2:48 AM
What about if there is a date time in my database and I want to update the data, but when I try to select that data to update, I get this error "String was not recognized as a valid date time"?
Hitori HitoriPosted May 12, 2021, 1:41 PM
Hi, could you lead me to fix database engine services that failed for SQL 2019,please ? :(((
terter SantosPosted May 3, 2021, 6:19 AM
Hi my code are showing message successfully updated but in datagridview and database are the same, nothing has changed. Thanks
Wilfred EghenedjiPosted Feb 23, 2021, 12:33 PM
Am working with Access as Database in C# (Visual Studio 15). I want to save form entries (add record) into the Access Database and would want the corresponding ID of the record to show upon successful saving.
Danson DansonPosted Apr 30, 2020, 1:59 PM
Hi. My records are showing update successful but when I check the database, nothing is updated, what could be the reason?
akhil saiPosted Oct 29, 2019, 2:48 AM
Hi. I am able to add records to the table but when I select the record in the datagridview to update the columns then it is showing "Please select to update". same problem with delete. Kindly give me a solution and problem?
Rosemary RoopnarinePosted Oct 27, 2019, 10:09 PM
Hi, I am able to add records to the table but when I select the record in the datagridview to update the columns are empty. Not sure what I am missing, if you can assist it would be appreciated.
Chikits GarotsPosted Oct 6, 2019, 1:28 PM
Hello, I've used Auto specification in ID, somehow the rowheader which i clicked from the datagridview isn't inserting in text boxes. Thanks for the help
Marcus SticherPosted Jun 7, 2019, 3:22 AM
Good afternoon Anoop, my problem still the same: no automatic insertion of Id Number, error message same I listed. There is no identity added on that column. "Cannot insert the value NULL into column 'Id'(....).tbl_Record'; column does not allow nulls. INSERT fails.
Uy Long Nguyễn ĐôngPosted Jun 6, 2019, 4:50 AM
I have an problem, my datatype in sql is smalldatetime, that was an Exception: System.Data.SqlClient.SqlException: 'Conversion failed when converting character string to smalldatetime data type.'
Marcus SticherPosted Jun 6, 2019, 12:38 AM
Cannot insert the value NULL into column 'Id',....dbo.tbl_Record'; column does not allow nulls. INSERT fails.
Marcus SticherPosted Jun 5, 2019, 4:57 AM
Why in my project the ID (PrKey) is not inserted in no way, only error message? thanks
Marcus SticherPosted Jun 5, 2019, 4:54 AM
Thank you very much for this helpful sample, nothing superb like this in msd sites!
Lalrinchhana KhalthangPosted Apr 15, 2019, 10:26 AM
How id ID number automatically counted
Lalrinchhana KhalthangPosted Apr 15, 2019, 10:26 AM
Why ID number 1,2,3,4,6 come, why not 5
Mahnoor NaeemPosted Mar 30, 2019, 6:36 PM
How to create dataGridView1_RowHeaderMouseClick Event??? I where I click in datagridView to create event please tell me??
Jim BrillantesPosted Mar 17, 2019, 5:14 AM
Good day, I followed your tutorial and did everything on it. It does save on the datagridview, but if I stop the program and check the database, there are no records saved and the datagridview will be empty again after re-running the program.
Valmy TesmoingtPosted Jan 26, 2019, 10:49 AM
Hello,Although this does not persist in the table, can you still tell me how to prevent changing the content of the datagridview, so that the only manipulation that can be made is to select a line? Thank you in advance.
elnaz AmanollahyPosted Dec 26, 2018, 11:14 PM
When a I select a row ,that info doesn't appear in the boxes
Jet WellPosted Sep 27, 2018, 8:02 PM
That's late reply but i appreciate you for this example
mp singhPosted May 29, 2018, 2:25 AM
When I have changed in adding two more textbox thenover the insert button is properly working but the update and delete button is not working....pls send me the correct code for update and delete in gridview on [email protected] u
Philip BowserPosted Jan 25, 2018, 9:52 AM
Update and Delete does not work at all it skips the IF statement in the delete.. and in the update button does not change the database values. Both problems seem to be related to the fact that ID int value stays at 0 when selecting row.
sophea veteyPosted Jan 15, 2018, 1:35 AM
Why i use for in datagridview row not datatable show in textbox.
Avinaash MendaPosted Jan 1, 2018, 3:45 AM
There is nothing mentioned about ID - It wont allow to edit or update or insert if its null.
Muhammad SulamanPosted Nov 23, 2017, 1:41 AM
I really appreciate your work bro, thank you for your convince
Swasthika DamlePosted Nov 14, 2017, 9:30 AM
Thank you so much!!!!!
vk sonyPosted Aug 13, 2017, 2:48 AM
Public void ExecStatement(String sql, List<SqlParameter> Parameters, SqlTransaction MyTrans) { using (SqlCommand cmd = SqlCmnd()) { cmd.CommandText = sql; cmd.Transaction = MyTrans; for (int i = 0; i < Parameters.Count; i++) cmd.Parameters.Add(Parameters[i]); cmd.ExecuteNonQuery(); } }
sathish kumarPosted Jul 27, 2017, 9:33 AM
Delete operation,update operation on grid not working,any property should change for data grid..? please tell me..datagrid click event not work..
sathish kumarPosted Jul 27, 2017, 9:31 AM
Data grid properties option change
Hammouzine MeddourPosted May 23, 2017, 9:21 AM
Pls sir, how to create the database, we use SQL server?
Aditya KumarPosted Mar 28, 2017, 5:06 AM
Sir you have written one airticle where you are showing datagrid view row on the condition based and changing the colur as well in windows application? Can you please post that airticle link here? Thanks.
Milo BeitiaPosted Mar 27, 2017, 12:05 AM
'DataTable' does not contain a definition for 'datasource' and no extension........
Worshipful MasterPosted Mar 6, 2017, 2:42 PM
No work, error in sql conection. Can you help me, Please !!! Where is error???
Ahmet OzkurtPosted Feb 20, 2017, 2:10 PM
Hi, can you set up to access.
ali ashrafiPosted Feb 17, 2017, 5:09 PM
In wpf application I don't have a rowheadermouseclick an I use the mouse double click an in this method don't have rows.[e.RowIndex]
ali ashrafiPosted Feb 17, 2017, 5:07 PM
This code is not work on wpf application ineed the wpf code in this part ???private?void?dataGridView1_RowHeaderMouseClick(object?sender,?DataGridViewCellMouseEventArgs?e)?? ????????{?? ????????????ID?=?Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());?? ????????????txt_Name.Text?=?dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();?? ????????????txt_State.Text?=?dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();?? ????????}
sunny sharmaPosted Feb 17, 2017, 7:06 AM
Nice oneIt keeps giving me connection error to the database by saying the following:
xinyu zhangPosted Jan 5, 2017, 3:41 PM
It keeps giving me connection error to the database by saying the following:
pooja sutharPosted Nov 30, 2016, 1:22 AM
Nice ..but how to show tinserted data into gridview which located at another webform
SHIVANI TRIPATHIPosted Nov 18, 2016, 10:47 AM
I'm having connection property has not been initialized error help....
Rajesh PawdePosted Oct 27, 2016, 7:13 AM
Nice One Thanks !!!
Buntu SubsPosted Oct 15, 2016, 4:39 AM
I Input Datasource path, but same error
Abhi SanghviPosted Sep 19, 2016, 10:05 PM
Now datagridview error some time note display the data and how to increase the column width like in your program name width
Abhi SanghviPosted Sep 17, 2016, 7:21 AM
Error in run time help me please
Harshit MehtaPosted Aug 23, 2016, 8:39 AM
What if there was a combobox field instead of a textbox field? For example, if there was a combobox for 'State' field inside the datagridview as well as outside the datagridview.
Laura AlmaPosted May 31, 2016, 11:08 PM
I'm beginning to learn c# by myself and this was really really helpful! i'm trying to figure out how to display the DataGridView and the Text Boxes in different forms right now, but this gave me a place where to start! Thank you so much!
kavita chavanPosted Mar 18, 2016, 4:36 AM
nice
Shraddha ChavanPosted Feb 23, 2016, 3:29 AM
what is ID in this code????
Chandu KumawatPosted Dec 29, 2015, 2:33 AM
nice
Vijay KumarPosted Dec 15, 2015, 9:54 AM
its
Anoop Kumar SharmaPosted Nov 17, 2015, 10:21 AM
Thanks Divya..!
DivyaPosted Nov 16, 2015, 12:21 AM
great its helpful . thank you sir
zosangzuala sailoPosted Nov 6, 2015, 4:25 AM
I cannot access the private variable(i.e variable dat is assign da datagridview value from another private.how can i access.thank u..
Raj KumarPosted Oct 20, 2015, 12:45 AM
What do I do if "DisplayData()" is considered an error. And there is an error message that reads: The name "DisplayData" does not exist in the current context. PLEASE HELP
bhushan raikwadPosted Oct 2, 2015, 5:51 AM
When I m select the row nt show me data in txtname and txtstate.
bhushan raikwadPosted Oct 2, 2015, 5:50 AM
Not use update and delete command
Shahbaz AhmadPosted Sep 1, 2015, 2:36 AM
its great but i need all are operation are must be inside datagrid not use outside like textbox and buttons ..
Anoop Kumar SharmaPosted Aug 7, 2015, 10:08 AM
Thanks Navnath Ugale..! :-)
Navnath UgalePosted Aug 7, 2015, 7:33 AM
Good Very nice !!!!!!!!!!!!!!
Alexander ChromePosted Jul 21, 2015, 10:01 PM
What do I do if "DisplayData()" is considered an error. And there is an error message that reads: The name "DisplayData" does not exist in the current context. PLEASE HELP
Anoop Kumar SharmaPosted Jul 5, 2015, 9:26 AM
Thanks nassim louchani
nassim louchaniPosted Jul 5, 2015, 2:53 AM
Good !
Anoop Kumar SharmaPosted May 25, 2015, 12:36 AM
You're Welcome.. majedul islam..!! :-)
majedul islamPosted May 23, 2015, 1:25 PM
thanks
Anoop Kumar SharmaPosted Apr 6, 2015, 12:22 PM
Thanks Karthik K..!!
Karthik KPosted Apr 6, 2015, 12:11 PM
Good one..
Anoop Kumar SharmaPosted Mar 23, 2015, 1:58 AM
Thanks Khargesh Rajput
Khargesh RajputPosted Mar 23, 2015, 12:04 AM
nice
Anoop Kumar SharmaPosted Mar 22, 2015, 7:00 AM
Thanks RAK?SH Sir.!
RakeshPosted Mar 22, 2015, 5:44 AM
good one :)
Sibeesh VenuPosted Mar 21, 2015, 11:04 PM
Anoop Kumar Sharma You are welcome.
Anoop Kumar SharmaPosted Mar 21, 2015, 10:18 PM
Thanks Sibeesh Venu SIr..!
Sibeesh VenuPosted Mar 21, 2015, 9:17 PM
Nice one.
Anoop Kumar SharmaPosted Mar 21, 2015, 1:26 PM
Thanks Gowtham Rajamanickam..!! :-)
Gowtham RajamanickamPosted Mar 21, 2015, 11:47 AM
good one...