G
gary
Hello I am trying to access my data using some of the examples on the VB Resource CD to learn about VB.net. I have used the following code:
Public Sub InsertRow(ByVal myConnectionString As String)
MyConnectionString = "database=Northwind;Server=localhost"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim myConnection As New SqlConnection
Dim myInsertQuery As String = "INSERT INTO Customers (CustomerID, CompanyName) Values('NWIND', 'Northwind Traders')"
Dim myCommand As New SqlCommand(myInsertQuery)
myCommand.Connection = myConnection
myConnection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
End Sub 'SelectSqlClientSrvRows
When I click f5 and run the app, I get no compile errors. When I click on the button, however and attempt to access the server, I get the following error:
An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
Additional information: The ConnectionString property has not been initialized.
Additional information is as follows:
1. I have Visual Studio.net installed with MSDE on my computer. In my server explorer I have the following items showing.
SQL Servers ---GARYLAP\INSTANCE--------
2. Under the GARYLAP\INSTANCE I have the following databases:
Master
Model
MSDB
Northwind
I have modified the connection string until I finally gave up. I tried server =garylap and garylap\instance but to no avail. Any help would be greatly appreciated.
Thanks,
Gary
Public Sub InsertRow(ByVal myConnectionString As String)
MyConnectionString = "database=Northwind;Server=localhost"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim myConnection As New SqlConnection
Dim myInsertQuery As String = "INSERT INTO Customers (CustomerID, CompanyName) Values('NWIND', 'Northwind Traders')"
Dim myCommand As New SqlCommand(myInsertQuery)
myCommand.Connection = myConnection
myConnection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()
End Sub 'SelectSqlClientSrvRows
When I click f5 and run the app, I get no compile errors. When I click on the button, however and attempt to access the server, I get the following error:
An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll
Additional information: The ConnectionString property has not been initialized.
Additional information is as follows:
1. I have Visual Studio.net installed with MSDE on my computer. In my server explorer I have the following items showing.
SQL Servers ---GARYLAP\INSTANCE--------
2. Under the GARYLAP\INSTANCE I have the following databases:
Master
Model
MSDB
Northwind
I have modified the connection string until I finally gave up. I tried server =garylap and garylap\instance but to no avail. Any help would be greatly appreciated.
Thanks,
Gary