i've a problem with deleting record from datagrid. i have few columns in my datatable and all publish on to a grid and under "ID" column there are id nos and they are "NOT" unique. user able to search using this "ID" no. problem comes in deleting records since the "ID" is not unique. if i use following command to delete; it deletes all the records which are having same "ID". but i want to delete only the current row records,

sqlDelete = "DELETE * FROM table1 WHERE ID ='" & form1.dgv1.CurrentRow.Cells(0).Value.ToString & "'"

any help. thanks in advance.

6 Years
Discussion Span
Last Post by M.Waqas Aslam

hello !
when ever there is a situation like this then always use two or more then two condition for updating and deleting records. for example . you have many fields in grid , one of them is ID and 2nd one is Name , just do like this

sqlDelete = "DELETE * FROM table1 WHERE ID ='" & form1.dgv1.CurrentRow.Cells(0).Value.ToString & "' and name='"& form1.dgv1.CurrentRow.Cells(0).Value.ToString & "'"

If please provide all columns name then i can able to provide you a good solution. if i helped you please mark this thread solved and vote me up .


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.