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.
VB.NET SQL Connection and SQL Command Error BC3002
Giacomo Raucci
346
Reputation points
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