Problem linking to specific Access Table

B

Burning_Ranger

I am having problems linking to the Order table (in my database). I get
an unhandled exception error in system.data.dll. The IDE points to:
daOrder.Fill(dtOrder) as the problem

My code:




Public Class fclsNewOrder
Inherits System.Windows.Forms.Form
Dim cnADONetConnection As New OleDb.OleDbConnection

Dim daCustomer As New OleDb.OleDbDataAdapter
Dim dtCustomer As New DataTable

Dim daProduct As New OleDb.OleDbDataAdapter
Dim dtProduct As New DataTable

Dim daOrder As New OleDb.OleDbDataAdapter
Dim dtOrder As New DataTable

Dim cbCommandBuilder As New OleDb.OleDbCommandBuilder
Dim intRowPos As Integer = 0


Private Sub fclsNewOrder_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load

cnADONetConnection.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\temp\turbobraze_test.mdb"

cnADONetConnection.Open()

daCustomer = New OleDb.OleDbDataAdapter("SELECT * FROM
Customer", cnADONetConnection)

daCustomer.Fill(dtCustomer)

daProduct = New OleDb.OleDbDataAdapter("SELECT * FROM Product",
cnADONetConnection)

daProduct.Fill(dtProduct)

daOrder = New OleDb.OleDbDataAdapter("SELECT * FROM Order",
cnADONetConnection)

daOrder.Fill(dtOrder)

cbCommandBuilder = New OleDb.OleDbCommandBuilder(daCustomer)
cbCommandBuilder = New OleDb.OleDbCommandBuilder(daProduct)
cbCommandBuilder = New OleDb.OleDbCommandBuilder(daOrder)
End Sub

Private Sub fclsNewOrder_Closed(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Closed
cnADONetConnection.Close()
End Sub

End Class





If I change the table name to Order2 or something else both in my code
and in my database it works OK, but just doesn't work as Order. There
are no other objects or entities in the database with the same name.
The other tables from the same database work fine.
 
M

Mark

Burn no longer Ranger :)

"Order" is an SQL keyword; either wrap it in square brackets (or double
quotes for Oracle), like so:

... OleDb.OleDbDataAdapter("SELECT * FROM [Order]" ...
or
... OleDb.OleDbDataAdapter("SELECT * FROM ""Order""" ... (Oracle)

.... OR change the name of your table :p

Cheers,
 
B

Burning_Ranger

Thanks! I was tearing my hair out wondering why such simple code
doesn't work.
 

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