I am new to VB.NET 2010 and I am trying to update my Access database.
I have an application running in VB6.0 and converted to VB 2010, but now I want to use a Datagridview and can't populate with a recordset. So, I am trying to test a new small program that works for displaying the data but cannot update.
It works when using the Northwind database but not with mine.
The code is as follows:
This small program I downloaded from Planet Source and works like a charm with, as I said, Northwind.
It gives the following error:
Syntax error (missing operator) in query expression '((ID = ?) AND ((? = 1 AND Quantity Available IS NULL) OR (Quantity Available = ?)) AND ((? = 1 AND Item Title IS NULL) OR (Item Title = ?)) AND ((? = 1 AND Item ID IS NULL) OR (Item ID = ?)) AND ((? = 1 AND Start Date IS NULL) OR (Start Date = ?)) AND ((?'.
The table has an ID (auto generated) as a primary key.
Thanks for your help
I have an application running in VB6.0 and converted to VB 2010, but now I want to use a Datagridview and can't populate with a recordset. So, I am trying to test a new small program that works for displaying the data but cannot update.
It works when using the Northwind database but not with mine.
The code is as follows:
Imports System.Data.OleDb
Public Class frmMSAccess
'Create connection
Dim conn As OleDbConnection
'create data adapter
Dim da As OleDbDataAdapter
'create dataset
Dim ds As DataSet = New DataSet
'Set up connection string
Dim cnString As String
Dim sqlQRY As String
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
'update customers table
da.Update(ds, "Active")
End Sub
Private Sub frmMSAccess_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cnString = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=..\data\Listings.mdb"
' sqlQRY = "SELECT * FROM Customers WHERE City = 'London' "
sqlQRY = "SELECT * FROM ActiveListings WHERE Status Is Null"
conn = New OleDbConnection(cnString)
Try
' Open connection
conn.Open()
da = New OleDbDataAdapter(sqlQRY, conn)
'create command builder
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(da)
'fill dataset
da.Fill(ds, "Active")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "Active"
Catch ex As OleDbException
MsgBox(ex.ToString)
Finally
' Close connection
conn.Close()
End Try
End Sub
End Class
This small program I downloaded from Planet Source and works like a charm with, as I said, Northwind.
It gives the following error:
Syntax error (missing operator) in query expression '((ID = ?) AND ((? = 1 AND Quantity Available IS NULL) OR (Quantity Available = ?)) AND ((? = 1 AND Item Title IS NULL) OR (Item Title = ?)) AND ((? = 1 AND Item ID IS NULL) OR (Item ID = ?)) AND ((? = 1 AND Start Date IS NULL) OR (Start Date = ?)) AND ((?'.
The table has an ID (auto generated) as a primary key.
Thanks for your help
Last edited by a moderator: