此错误'查询表达式'项ID'中的语法错误(缺少运算符)。'当我尝试将数据添加到数据库时总会出现。有人可以帮忙吗?谢谢
Private Sub RefreshData()
If Not cnn.State = ConnectionState.Open Then
'open connection
cnn.Open()
End If
Dim da As New OleDb.OleDbDataAdapter("SELECT Item ID as [Item ID], " & _
"Item Name as [Item Name], " & _
"Item Type as [Item Type], " & _
"Quantity as [Quantity], " & _
"Min Shelf Stock as [Min Shelf Stock], " & _
"Purchase Price as [Purchase Price], Note " & _
" From Product ORDER BY Item ID", cnn)
Dim dt As New DataTable
'fill data to datatable
da.Fill(dt)
'offer data in data table into datagridview
Me.dgvData.DataSource = dt
'Close the connection
cnn.Close()
End Sub
答案 0 :(得分:1)
将[]放在列名称周围。例如:物品ID = [物料ID] 对所有列名称执行此操作
SELECT Item ID as [Item ID], " & _
"Item Name as [Item Name], " & _
"Item Type as [Item Type], " & _
"Quantity as [Quantity], " & _
"Min Shelf Stock as [Min Shelf Stock], " & _
"Purchase Price as [Purchase Price], Note " & _
" From Product ORDER BY Item ID",
更改为:
SELECT [Item ID], " & _
"[Item Name], " & _
"[Item Type], " & _
"[Quantity], " & _
"[Min Shelf Stock], " & _
"[Purchase Price], Note " & _
" From Product ORDER BY Item ID",