I am new to c# and SQL server. I am currently using SQL management tool to create tables and have added table to data gridview visually while I can enter the data the table as well as the data base is updated but I cannot delete rows from the data base although a row seems to be deleted when I delete the selected row it appears again when I recompile since the database is not updated.

I am using the following code in the update button


whenever i run the program and delete a row and push the update button there is a error saying proper update method is required to delete a row.

isn't the code above enough to update a row or delete it if we add tables to datagrid view visually.

please help
thank u

If you're deleting it visually then there is no need to call .Update() and .Fill() on the table adapter. Just call .Delete() on the row and then .AcceptChanges() on the dataset to finalize the delete without persisting the changes.

.Delete () on row?. I am new to SQL so please can you provide me syntax thank you.

isn't the code above enough to update a row or delete it if we add tables to datagrid view visually.

I don't understand why SQL is involved here if we're doing it all visually (thus not wanting to commit changes to the SQL Server). In the dataset delete the row:


I have tried it. It deletes the row but when I run the program again the row deleted row appears again.

please help

That is because it did not push the changes to the database because you only wanted to visually delete the row, which the way I understand it means only remove it from the grid/dataset but not the database.

Thanks for the reply,

so if I add table visually in the datagrid view can't I delete the row from the database as well?

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.