Skip to content
Advertisement

Delete row in datagridview and database with C#

I made a database and a program with a datagridview to show the database content. Now I want to make a button to let users delete a row and delete it also in the database.

I tried the following solution which I found in Stackoverflow: How to delete row datagrid..

But I get following Error: enter image description here

The error tells me that the type SqlConnection was not found.

My whole code I’ve linked here:Pastebin

Advertisement

Answer

You need to add a reference to System.Data.SqlClient.

In Visual Studio you can expand a project, right-click on References and click on Add Reference, navigate to the actual reference and add it to the project. See: https://docs.microsoft.com/en-us/visualstudio/ide/managing-references-in-a-project?view=vs-2019

Also see: https://docs.microsoft.com/en-us/visualstudio/ide/how-to-add-or-remove-references-by-using-the-reference-manager?view=vs-2019

If a reference is missing, then you can download it via the NuGet Package Manager.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement