Custom Class with oledbcommand problem

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
 
C

Cypher Drive

Cor,

Starting on this line :

dap1.SelectCommand = New OleDb.OleDbCommand("SELECT CustomerID,
: )
 
C

Cypher Drive

Patrice, Cor,

Thanks.





Patrice said:
Looks my previous response was lost. Code should be enclosed in a sub or
function statement. Here you just put your code following data
declaration...
 
C

Cor Ligthert[MVP]

Cypher Drive,

To be honest, I never use it like that, I always set the select clause in
the constructor of the adapter.

Dim adapter As OleDbDataAdapter = _
New OleDbDataAdapter(selectCommand, connection)


Cor
 
C

Cypher Drive

Cor,

Thanks so much.

Regards,

Cyp Dr

Cor Ligthert said:
Cypher Drive,

To be honest, I never use it like that, I always set the select clause in
the constructor of the adapter.

Dim adapter As OleDbDataAdapter = _
New OleDbDataAdapter(selectCommand, connection)


Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top