VB.NET SQL Connection and SQL Command Error BC3002

Giacomo Raucci 366 Reputation points
2024-04-16T16:02:09.4533333+00:00

Hello, I'm in the process of converting VBA to VB.NET with SQL statements. One of the changes is utilizing the "ExecuteNonQuery". Since I'm still learning the syntax, I simply copied the VB.NET statements from a web-site. But I'm getting 2 errors: #1. error "BC3002 Type 'SqlConnection' is not defined" and #2. error BC3002 Type 'SQLCommand' is not defined" when compiling using Visual Studio 2022. I included the IMPORTS statement, Imports System.Data.SqlClient as well, but still these 2 compiler errors.  What else do I need to do?  Thanks

Imports System.Data.SqlClient


Dim name As String = "Mudassar Khan"

    Dim city As String = "Pune"

    Dim constring As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString

    Using con As New SqlConnection(constring)

        Using cmd As New SqlCommand("UPDATE Persons SET City = @City WHERE Name = @Name", con)

            cmd.CommandType = CommandType.Text

            cmd.Parameters.AddWithValue("@Name", name)

            cmd.Parameters.AddWithValue("@City", city)

            con.Open()

            Dim rowsAffected As Integer = cmd.ExecuteNonQuery()

            con.Close()

        End Using

    End Using

SQL Server | SQL Server Transact-SQL
Developer technologies | VB
Developer technologies | Transact-SQL
Developer technologies | Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Viorel 126.1K Reputation points
    2024-04-16T17:10:01.7633333+00:00

    Try to select the “Manage NuGet Packages” command from PROJECT menu, go to Browse tab, and install the System.Data.SqlClient package. Then rebuild the project.

    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.