In an attempt to learn how to add a record to an existing table in my sql server database, I have created a form that contains nothing but a button. When the button is clicked I want to add a record to my table (tblController).
The code that I am using is adapted from an msdn doc.
Here's the code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myConnectionString As String = _
"Data Source=(local);Initial Catalog=Trackster;user id=foo; password=bar"
Dim myConnection As New SqlConnection(myConnectionString)
Dim myInsertQuery As String = "INSERT INTO tblController (sName) Values('this is a test')"
Dim myCommand As New SqlCommand(myInsertQuery)
myCommand.Connection = myConnection
myConnection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
End Sub
Here's the problem:
When I attempt to compile the code, I receive a couple of error messages:
1. Type 'SqlConnection' is not defined
2. Type 'SqlCommand' is not defined
Can anyone fill me in on why I am receiving this error messages and how to fix the problem. If you don't know what's causing the error, but have a working sample of how to add a record to a table, that would be great too!
I am running:
Visual Studio .NET 2003
SQLServer 2000 Enterprise
Windows 2000
btw: I am an absolute beginner to VB / Studio.
Thanks
The code that I am using is adapted from an msdn doc.
Here's the code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myConnectionString As String = _
"Data Source=(local);Initial Catalog=Trackster;user id=foo; password=bar"
Dim myConnection As New SqlConnection(myConnectionString)
Dim myInsertQuery As String = "INSERT INTO tblController (sName) Values('this is a test')"
Dim myCommand As New SqlCommand(myInsertQuery)
myCommand.Connection = myConnection
myConnection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
End Sub
Here's the problem:
When I attempt to compile the code, I receive a couple of error messages:
1. Type 'SqlConnection' is not defined
2. Type 'SqlCommand' is not defined
Can anyone fill me in on why I am receiving this error messages and how to fix the problem. If you don't know what's causing the error, but have a working sample of how to add a record to a table, that would be great too!
I am running:
Visual Studio .NET 2003
SQLServer 2000 Enterprise
Windows 2000
btw: I am an absolute beginner to VB / Studio.
Thanks