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

Recommended Answers

All 5 Replies

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

commented: You shouldn't be voted down for stating a fact. Therefore, I voted you back up. +5

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")
con.open()
dim da as new sqldataadapter("select id,name from table",con)
dim dt as new datatable
da.fill(dt)
datagrid.datasource = dt 
con.close

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")
con.open()
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
cmd.executenonquery() 
con.close
next

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.

Regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.