Has anyone had any problems with making a connection to the Northwind database using the OleDbConnection
described in chapter 9 in the Executing Commands Directory example?
I find that my browser shows a compilation error at line 8 which is where we call the open method of the OleDbConnection?
I.e. dbConnection.open on which the compiler is looking for a new declaration suggesting that the link has not been made.
ERROR REPORT
Server Error in '/BookASP_NET' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request.
Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30188: Declaration expected.
Source Error:
Line 6: "Data Source=C:\BegASPNET11\data\Northwind.mdb"
Line 7: Dim dbConnection As New OleDbConnection(connectionString)
Line 8: dbConnection.Open()
Line 9: Line 10: Dim commandString As String = "INSERT INTO Employees(FirstName, LastName) " & _
Source File: c:\inetpub\wwwroot\BookASP_NET\CH9\CommandExecute. aspx Line: 8
Source Code
<%@ Import Namespace="System.Data.OleDB" %>
<%@ Page Language="
vb" %>
<script runat="server">
Dim connectionString = "Provider=Microsoft.jet.OLEDB.4.0; " & _
"Data Source=C:\BegASPNET11\data\Northwind.mdb"
Dim dbConnection As New OleDbConnection(connectionString)
dbConnection.Open() <-----Error line: compiler requires this declared
Dim commandString As String = "INSERT INTO Employees(FirstName, LastName) " & _
"Values(@FirstName, @LastName)"
Dim dbCommand As New OleDbCommand(commandString, dbConnection)
Dim firstNameParam As New OleDbParameter("@FirstName", OleDBType.VarChar, 10)
firstNameParam.Value = txtFirstName.Text
dbCommand.Parameters.Add(firstNameParam)
Dim lastNameParam As New OleDbParameter("@LastName", OleDbType.VarChar, 20)
lastNameParam.Value = txtLastName.Text
dbCommand.Parameters.Add(lastNameParam)
dbCommand.ExecuteNonQuery()
dbConnection.Close()
</script>
Note: this code is what I have taken from the book, continuation characters are used where the line is too long for a single line entry - other broken lines are due to the word wrapping of this topic forms table element. I have not listed the HTML bit at the bottom.