hello everyone i just wanna ask some help regarding on how to delete all datas in the data grid view from search result.

i have a form which search data in specific date and show result in the datagridview, what i want is that when delete button is clicked all datas that in the datagridview will be deleted sameway in the database

Recommended Answers

All 3 Replies

hello !
you can perform your required function like this

dim myCon as new sqlconnection("connection string")
dim cmd as new sqlcommand
dim i as integer
myCon.open()
for i = 0 to datagrid1.rows.count -1 
   cmd.commandtext = "delete from table1 where RecID=@RecID"
   cmd.connection = myCon
   cmd.parameter.addwithvalue("@RecID",datagrid1.item(0,i).value)
   cmd.executenonquery()
next
myCon.close

i write this code here in posting thread textbox so may be there is some spelling mistake , but i hope even if this will not solve your prob but this will give you a idea to solve your prob.(sorry for bad english)

Regards

M.Waqas Aslam

hello !
you can perform your required function like this

dim myCon as new sqlconnection("connection string")
dim cmd as new sqlcommand
dim i as integer
myCon.open()
for i = 0 to datagrid1.rows.count -1 
   cmd.commandtext = "delete from table1 where RecID=@RecID"
   cmd.connection = myCon
   cmd.parameter.addwithvalue("@RecID",datagrid1.item(0,i).value)
   cmd.executenonquery()
next
myCon.close

i write this code here in posting thread textbox so may be there is some spelling mistake , but i hope even if this will not solve your prob but this will give you a idea to solve your prob.(sorry for bad english)

Regards

M.Waqas Aslam

it give me this error :

"Parameters @myParam has already been defined"

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.