473,395 Members | 1,616 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

OleDbDataAdapter Update failure

Al
Hi,
I need to update tables in access 97. The table names have spaces (not my
choice). My update fails even though I use the OleDbCommandBuilder.
Here is a code I am using

myDataAdapter = New OleDbDataAdapter
myDataAdapter.SelectCommand = New OleDbCommand("Select * from [Patient
Table]", MyConnection)
Dim cb As OleDbCommandBuilder = New
OleDbCommandBuilder(PatientsBillingDataAdapter)

‘Updating dataset ……….
myDataAdapter.Update(aDataset, aTableName)

I get syntax error in update statement…

Any suggestion is very much appreciated

Thanks

Al

Nov 21 '05 #1
5 3675
Al
the last line of code is
Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(myDataAdapter )
"Al" wrote:
Hi,
I need to update tables in access 97. The table names have spaces (not my
choice). My update fails even though I use the OleDbCommandBuilder.
Here is a code I am using

myDataAdapter = New OleDbDataAdapter
myDataAdapter.SelectCommand = New OleDbCommand("Select * from [Patient
Table]", MyConnection)
Dim cb As OleDbCommandBuilder = New
OleDbCommandBuilder(PatientsBillingDataAdapter)

‘Updating dataset ……….
myDataAdapter.Update(aDataset, aTableName)

I get syntax error in update statement…

Any suggestion is very much appreciated

Thanks

Al

Nov 21 '05 #2
If you look at the OleDbCommandBuilder GetUpdateCommand.CommandText property,
you will see that it places question marks where the OleDbParameters would
assign the values.

The next question on this board is similar to yours. You might like to read
my answer there.

"Al" wrote:
Hi,
I need to update tables in access 97. The table names have spaces (not my
choice). My update fails even though I use the OleDbCommandBuilder.
Here is a code I am using

myDataAdapter = New OleDbDataAdapter
myDataAdapter.SelectCommand = New OleDbCommand("Select * from [Patient
Table]", MyConnection)
Dim cb As OleDbCommandBuilder = New
OleDbCommandBuilder(PatientsBillingDataAdapter)

‘Updating dataset ……….
myDataAdapter.Update(aDataset, aTableName)

I get syntax error in update statement…

Any suggestion is very much appreciated

Thanks

Al

Nov 21 '05 #3
Al
Hi Charlie,
The problem as you pointed out is table name [patient Table] where it
convert it to '[Patient Table]' and then cannot find it. I didn't follow
Update is there a sample code out there i can use? I am at lost
Thanks
Al

"Charlie" wrote:
If you look at the OleDbCommandBuilder GetUpdateCommand.CommandText property,
you will see that it places question marks where the OleDbParameters would
assign the values.

The next question on this board is similar to yours. You might like to read
my answer there.

"Al" wrote:
Hi,
I need to update tables in access 97. The table names have spaces (not my
choice). My update fails even though I use the OleDbCommandBuilder.
Here is a code I am using

myDataAdapter = New OleDbDataAdapter
myDataAdapter.SelectCommand = New OleDbCommand("Select * from [Patient
Table]", MyConnection)
Dim cb As OleDbCommandBuilder = New
OleDbCommandBuilder(PatientsBillingDataAdapter)

‘Updating dataset ……….
myDataAdapter.Update(aDataset, aTableName)

I get syntax error in update statement…

Any suggestion is very much appreciated

Thanks

Al

Nov 21 '05 #4
For your Select, write your own SELECT statement, and WHERE clause, using the
"[]" where needed. Pass the SELECT statement and your Connection as
parameters to a DataAdapter. Then use the DataAdapter.Fill method, passing
the DataTable you want to fill as a parameter to the DataAdapter. If the
DataTable has been filled before, use DataTable.Rows.Clear first. When you
use DataAdapter.Fill, pass the Connection in the Closed state. The
DataAdapter will open and close it for you.

To write to the database, use a Command object. Create an UPDATE, INSERT,
or DELETE statement by concatenating the values to be affected into the
syntax of the statement. The syntax of any of those statements is easy to
find on the web. BE SURE to use a WHERE clause (e.g. WHERE PrimaryKey =
1000) for UPDATE or DELETE. Pass the statement and the Connection to the
Command object as you instantiate the Command. Open the Connection. Use
YourCommand.ExecuteNonQuery. Close the Connection.

Also, I tested to make sure that a space in a bracketed table name would
work, and it did. Put the YourCommand.ExecuteNonQuery in a Try Block and see
what error you get. Post your exact statement in a new thread if there is a
syntax error that you can't resolve. Be sure to use single quotes for string
values, no quotes for numeric, #date# for dates.

You don't need the CommandBuilder. You don't need to have the DataAdapter
involved when writing back to the database, just the OleDbCommand.

"Al" wrote:
Hi,
I need to update tables in access 97. The table names have spaces (not my
choice). My update fails even though I use the OleDbCommandBuilder.
Here is a code I am using

myDataAdapter = New OleDbDataAdapter
myDataAdapter.SelectCommand = New OleDbCommand("Select * from [Patient
Table]", MyConnection)
Dim cb As OleDbCommandBuilder = New
OleDbCommandBuilder(PatientsBillingDataAdapter)

‘Updating dataset ……….
myDataAdapter.Update(aDataset, aTableName)

I get syntax error in update statement…

Any suggestion is very much appreciated

Thanks

Al

Nov 21 '05 #5
For your Select, write your own SELECT statement, and WHERE clause, using the
"[]" where needed. Pass the SELECT statement and your Connection as
parameters to a DataAdapter. Then use the DataAdapter.Fill method, passing
the DataTable you want to fill as a parameter to the DataAdapter. If the
DataTable has been filled before, use DataTable.Rows.Clear first. When you
use DataAdapter.Fill, pass the Connection in the Closed state. The
DataAdapter will open and close it for you.

To write to the database, use a Command object. Create an UPDATE, INSERT,
or DELETE statement by concatenating the values to be affected into the
syntax of the statement. The syntax of any of those statements is easy to
find on the web. BE SURE to use a WHERE clause (e.g. WHERE PrimaryKey =
1000) for UPDATE or DELETE. Pass the statement and the Connection to the
Command object as you instantiate the Command. Open the Connection. Use
YourCommand.ExecuteNonQuery. Close the Connection.

Also, I tested to make sure that a space in a bracketed table name would
work, and it did. Put the YourCommand.ExecuteNonQuery in a Try Block and see
what error you get. Post your exact statement in a new thread if there is a
syntax error that you can't resolve. Be sure to use single quotes for string
values, no quotes for numeric, #date# for dates.

You don't need the CommandBuilder. You don't need to have the DataAdapter
involved when writing back to the database, just the OleDbCommand.

"Al" wrote:
Hi,
I need to update tables in access 97. The table names have spaces (not my
choice). My update fails even though I use the OleDbCommandBuilder.
Here is a code I am using

myDataAdapter = New OleDbDataAdapter
myDataAdapter.SelectCommand = New OleDbCommand("Select * from [Patient
Table]", MyConnection)
Dim cb As OleDbCommandBuilder = New
OleDbCommandBuilder(PatientsBillingDataAdapter)

‘Updating dataset ……….
myDataAdapter.Update(aDataset, aTableName)

I get syntax error in update statement…

Any suggestion is very much appreciated

Thanks

Al

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bob | last post by:
Hi.. I'm making a OleDb connection to a access database.. I can fill the dataset fine and view the data, but when I add a new row and try to update the db I get this error. Any help would be...
2
by: Son Ha | last post by:
I want to copy some record from a Access database to another Access DB. My code as follow but not working. The destAdapter.Update() return 0 record affected. Tell me what's wrong in my code? ...
1
by: Bennett Haselton | last post by:
Suppose I add a new row to a table in a dataset, and then I use an OleDbDataAdapter to add that new row to a SQL Server database using OleDbDataAdapter.Update(), as in the following code: ...
9
by: joun | last post by:
Hi all, i'm using this code to insert records into an Access table from asp.net, using a stored procedure, called qry_InsertData: PARAMETERS Long, Long, Text(20), Long, DateTime; INSERT...
0
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database...
1
by: RML | last post by:
Hi everyone, I am using VB.NET 2003 and an OleDBDataAdapter to update an Access table's DateTime field. The field's format is set to "General Date" (ie: 11/24/2004 8:00:00 AM). The problem is...
6
by: tom c | last post by:
I create 2 data OleDbDataAdapters, one with the wizard, and one in code. I know the adapter created in code is OK because I use it to fill a data table. However, when I try to use the same SQL...
2
by: explode | last post by:
I made nova oledbdataadapter select update insert and delete command and connection veza. dataset is Studenti1data, I made it by the new data source wizard,and made datagridview and bindingsource...
6
by: baldrick | last post by:
Hello, I am trying to plonk the entire contents of a dBase file into an Access table. I have scanned the dBase fields and created an empty Access table with the same field formats. I have...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.