C
Cypher Drive
Dear all,
Please help with this one.
Error on dap1 -
Error is "DECLARATION EXPECTED"
I'm using visual studio.net 2005 and ms access 2003. thanks....
Trying to create a data class with the following codes:
Public Class OpenMDB
'Instantiate dap1 as an OleDbDataAdapter instance
Dim dap1 As New OleDb.OleDbDataAdapter()
'Instantiate das1 as a DataSet instance
Dim das1 As New System.Data.DataSet()
'Declare and instantiate Connection and Command objects
Dim cnn1 As New OleDb.OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\Program Files\" & _
"Microsoft Office\Office10\Samples\Northwind.mdb")
'Specify SelectCommand, InsertCommand, UpdateCommand,
'and DeleteCommand properties
dap1.SelectCommand = New OleDb.OleDbCommand("SELECT CustomerID,
CompanyName " & "FROM Customers", cnn1)
dap1.InsertCommand = New OleDb.OleDbCommand("INSERT INTO Customers " &
"(CustomerID, CompanyName) " & "VALUES (?, ?)", cnn1)
dap1.UpdateCommand = New OleDb.OleDbCommand("Update Customers SET
CustomerID = ?, " & "CompanyName = ? WHERE CustomerID = ?", cnn1)
dap1.DeleteCommand = New OleDb.OleDbCommand("DELETE FROM Customers WHERE
CustomerID = ?", cnn1)
'Specify parameters for InsertCommand
dap1.InsertCommand.Parameters.Add("@CustomerID", OleDb.OleDbType.Char,
5, "CustomerID")
dap1.InsertCommand.Parameters.Add("@CompanyName",
OleDb.OleDbType.VarChar, 40, "CompanyName")
'Specify parameters for UpdateCommand
dap1.UpdateCommand.Parameters.Add("@CustomerID", OleDb.OleDbType.Char,
5, "CustomerID")
dap1.UpdateCommand.Parameters.Add("@CompanyName",
OleDb.OleDbType.VarChar, 40, "CompanyName")
dap1.UpdateCommand.Parameters.Add("@oldCustomerID",
OleDb.OleDbType.Char, 5, "CustomerID").SourceVersion =
DataRowVersion.Original
'Specify parameters for DeleteCommand
dap1.DeleteCommand.Parameters.Add("@oldCustomerID",OleDb.OleDbType.Char,
5, "CustomerID").SourceVersion = DataRowVersion.Original
'Populate das1
dap1.Fill(das1, "CustomerIDsNames")
'Define a primary key for the DataTable
das1.Tables(0).PrimaryKey = New
DataColumn(){das1.Tables(0).Columns("CustomerID")}
End Class
Please help with this one.
Error on dap1 -
Error is "DECLARATION EXPECTED"
I'm using visual studio.net 2005 and ms access 2003. thanks....
Trying to create a data class with the following codes:
Public Class OpenMDB
'Instantiate dap1 as an OleDbDataAdapter instance
Dim dap1 As New OleDb.OleDbDataAdapter()
'Instantiate das1 as a DataSet instance
Dim das1 As New System.Data.DataSet()
'Declare and instantiate Connection and Command objects
Dim cnn1 As New OleDb.OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=c:\Program Files\" & _
"Microsoft Office\Office10\Samples\Northwind.mdb")
'Specify SelectCommand, InsertCommand, UpdateCommand,
'and DeleteCommand properties
dap1.SelectCommand = New OleDb.OleDbCommand("SELECT CustomerID,
CompanyName " & "FROM Customers", cnn1)
dap1.InsertCommand = New OleDb.OleDbCommand("INSERT INTO Customers " &
"(CustomerID, CompanyName) " & "VALUES (?, ?)", cnn1)
dap1.UpdateCommand = New OleDb.OleDbCommand("Update Customers SET
CustomerID = ?, " & "CompanyName = ? WHERE CustomerID = ?", cnn1)
dap1.DeleteCommand = New OleDb.OleDbCommand("DELETE FROM Customers WHERE
CustomerID = ?", cnn1)
'Specify parameters for InsertCommand
dap1.InsertCommand.Parameters.Add("@CustomerID", OleDb.OleDbType.Char,
5, "CustomerID")
dap1.InsertCommand.Parameters.Add("@CompanyName",
OleDb.OleDbType.VarChar, 40, "CompanyName")
'Specify parameters for UpdateCommand
dap1.UpdateCommand.Parameters.Add("@CustomerID", OleDb.OleDbType.Char,
5, "CustomerID")
dap1.UpdateCommand.Parameters.Add("@CompanyName",
OleDb.OleDbType.VarChar, 40, "CompanyName")
dap1.UpdateCommand.Parameters.Add("@oldCustomerID",
OleDb.OleDbType.Char, 5, "CustomerID").SourceVersion =
DataRowVersion.Original
'Specify parameters for DeleteCommand
dap1.DeleteCommand.Parameters.Add("@oldCustomerID",OleDb.OleDbType.Char,
5, "CustomerID").SourceVersion = DataRowVersion.Original
'Populate das1
dap1.Fill(das1, "CustomerIDsNames")
'Define a primary key for the DataTable
das1.Tables(0).PrimaryKey = New
DataColumn(){das1.Tables(0).Columns("CustomerID")}
End Class