0

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

4
Contributors
3
Replies
5
Views
5 Years
Discussion Span
Last Post by artemix22
Featured Replies
  • hello ! you can perform your required function like this [CODE] 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 [/CODE] i … Read More

1

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

0

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"

This question has already been answered. 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.