VB.NET SQL Connection and SQL Command Error BC3002

Giacomo Raucci 321 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

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,575 questions
SQL Server Transact-SQL
SQL Server Transact-SQL
SQL Server: A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.Transact-SQL: A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
42 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,553 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 112.4K 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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful