Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

May be it's a simple problem. I used a datagridview in my form. I can insert record in datagridview. Now I want to delete selected row or record from datagridview that means this record also be deleted from database(MS access). But I have no primary key or identify key by which you can easily search this row. I am just want to use only row number of datagridview and delete record from database.
Posted
Comments
sjelen 24-Sep-12 11:35am    
You can't. You need a way to uniquely identify a record you want to delete in the database.
Otherwise, you might accidentally delete multiple records.
DataGrid's row number does not have anything to do with database - it's generated in code, not in DB.

1 solution

Have a column in your data grid view that is the ID of the record from the table, if you so desire, hide this column in code and that way you'll just have to get the focused row cell value and the perform any of your actions based on that. So if you have a click event, inside your click event you get the cell value, then perform your DELETE query within this bit of code.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900