Adapter Update...Syntax error

G

Guest

I have a simple Access database and I'm using VB.net. I'm getting a syntax
error on the update line. Any idea what needs to be fixed

Dim CX As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " &
Application.StartupPath & "\zAdmin.mdb;User Id=admin;Password=;"
Dim PWConn As New OleDbConnection(CX)

PWConn.Open()
SQL = "Select * from Admin"
Dim AdDataSet As New DataSet
Dim AdAdapter As New OleDbDataAdapter(SQL, PWConn)
AdAdapter.Fill(AdDataSet, "Admin")
Dim MyCommandBuilder As New OleDbCommandBuilder(AdAdapter)
AdAdapter.InsertCommand = MyCommandBuilder.GetInsertCommand
AdAdapter.UpdateCommand = MyCommandBuilder.GetUpdateCommand
Dim PwTable As DataTable

PwTable = AdDataSet.Tables("Admin")
PwTable.Rows(0)("Password") = "charlie"
AdAdapter.Update(AdDataSet, "Admin")
AdDataSet.AcceptChanges()
PWConn.Close()

Thanks
 
G

Guest

Hi,

Generally that is caused by a keyword being used a column name for your
admin table. Surrounding the column name in [ ] will fix the problem. A
simple fix is to change

Select * from Admin

to

Select [col1], [col2], [col3] from Admin

Ken
 
G

Guest

That did it ...thanks...

Ken Tucker said:
Hi,

Generally that is caused by a keyword being used a column name for your
admin table. Surrounding the column name in [ ] will fix the problem. A
simple fix is to change

Select * from Admin

to

Select [col1], [col2], [col3] from Admin

Ken
-------------------------------------

Arne Beruldsen said:
I have a simple Access database and I'm using VB.net. I'm getting a syntax
error on the update line. Any idea what needs to be fixed

Dim CX As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " &
Application.StartupPath & "\zAdmin.mdb;User Id=admin;Password=;"
Dim PWConn As New OleDbConnection(CX)

PWConn.Open()
SQL = "Select * from Admin"
Dim AdDataSet As New DataSet
Dim AdAdapter As New OleDbDataAdapter(SQL, PWConn)
AdAdapter.Fill(AdDataSet, "Admin")
Dim MyCommandBuilder As New OleDbCommandBuilder(AdAdapter)
AdAdapter.InsertCommand = MyCommandBuilder.GetInsertCommand
AdAdapter.UpdateCommand = MyCommandBuilder.GetUpdateCommand
Dim PwTable As DataTable

PwTable = AdDataSet.Tables("Admin")
PwTable.Rows(0)("Password") = "charlie"
AdAdapter.Update(AdDataSet, "Admin")
AdDataSet.AcceptChanges()
PWConn.Close()

Thanks
 
C

Cor Ligthert [MVP]

Arne,

Why are you trying to screw up your dataadapter with setting an insert
command that is already not used because the dynamicly build one in the
commandbuilder is used?

Cor

Arne Beruldsen said:
That did it ...thanks...

Ken Tucker said:
Hi,

Generally that is caused by a keyword being used a column name for
your
admin table. Surrounding the column name in [ ] will fix the problem. A
simple fix is to change

Select * from Admin

to

Select [col1], [col2], [col3] from Admin

Ken
-------------------------------------

Arne Beruldsen said:
I have a simple Access database and I'm using VB.net. I'm getting a
syntax
error on the update line. Any idea what needs to be fixed

Dim CX As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " &
Application.StartupPath & "\zAdmin.mdb;User Id=admin;Password=;"
Dim PWConn As New OleDbConnection(CX)

PWConn.Open()
SQL = "Select * from Admin"
Dim AdDataSet As New DataSet
Dim AdAdapter As New OleDbDataAdapter(SQL, PWConn)
AdAdapter.Fill(AdDataSet, "Admin")
Dim MyCommandBuilder As New OleDbCommandBuilder(AdAdapter)
AdAdapter.InsertCommand = MyCommandBuilder.GetInsertCommand
AdAdapter.UpdateCommand = MyCommandBuilder.GetUpdateCommand
Dim PwTable As DataTable

PwTable = AdDataSet.Tables("Admin")
PwTable.Rows(0)("Password") = "charlie"
AdAdapter.Update(AdDataSet, "Admin")
AdDataSet.AcceptChanges()
PWConn.Close()

Thanks
 

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