I am currently working on an application.. Am using datagridview validation for it.. i fix the datasource of the datagridview at runtime.. if i press the update button al the values in the datagridview cells should be updated in the table.. even if i update 100 cells it should be updated into my table.. pls help me with a good solution

4 Years
Discussion Span
Last Post by M.Waqas Aslam

what you had done so for ?? , please show some efforts then we will help you in this.

Votes + Comments
You shouldn't be voted down for stating a fact. Therefore, I voted you back up.

i havnt done anything so far.. i want to implement the datagridview validation tats y am asking here.. how to update al the values in a datagridview into the database table ?


ok , first we have to show values in grid

dim con as new sqlconnection("connectionstring")
dim da as new sqldataadapter("select id,name from table",con)
dim dt as new datatable
datagrid.datasource = dt 

now above code will show records id and name from table table , so now we have to update the records from the grid after making change , do like this

for i = 0 to datagrid.rows.count-1 
dim con as new sqlconnection("connectionstring")
dim i as integer
dim cmd as new sqlcommand 
cmd.commandtext = "update table set name='"& datagrid.item(1,i).value.tostring &" where id=" val(datagrid.item(0,i).values.tostring)
cmd.connection = con

this will update field name , note: as i type all this code here , so may be there are some spelling mistakes , please do not copy paste , first understand the code then start writing , without efforts there is no learning ,

Best Regards


Thanks to al ur efforts but i got the solution myself.. I have a new prob now.. I hav used the update query in the cellstatechanged event.. when i click on a datagridview which has no value i get the " OBJECT REFERENCE NOT SET TO AN INSTANCE OF AN OBJECT " exception.. I want to get the rowindex of an empty cell but i keep getting tis exception.. Can anyone help me wit this ?


please you have to know two things , 1- after getting solved please mark the thread solved , 2- always start new thread for your new question . it is better to ask your question in new thread and mark this solved , also please also post your code in which you have a prob.


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.