473,837 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OleDbDataAdapte r 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 OleDbCommandBui lder.
Here is a code I am using

myDataAdapter = New OleDbDataAdapte r
myDataAdapter.S electCommand = New OleDbCommand("S elect * from [Patient
Table]", MyConnection)
Dim cb As OleDbCommandBui lder = New
OleDbCommandBui lder(PatientsBi llingDataAdapte r)

‘Updating dataset ……….
myDataAdapter.U pdate(aDataset, aTableName)

I get syntax error in update statement…

Any suggestion is very much appreciated

Thanks

Al

Nov 21 '05 #1
5 3701
Al
the last line of code is
Dim cb As OleDbCommandBui lder = New OleDbCommandBui lder(myDataAdap ter )
"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 OleDbCommandBui lder.
Here is a code I am using

myDataAdapter = New OleDbDataAdapte r
myDataAdapter.S electCommand = New OleDbCommand("S elect * from [Patient
Table]", MyConnection)
Dim cb As OleDbCommandBui lder = New
OleDbCommandBui lder(PatientsBi llingDataAdapte r)

‘Updating dataset ……….
myDataAdapter.U pdate(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 OleDbCommandBui lder GetUpdateComman d.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 OleDbCommandBui lder.
Here is a code I am using

myDataAdapter = New OleDbDataAdapte r
myDataAdapter.S electCommand = New OleDbCommand("S elect * from [Patient
Table]", MyConnection)
Dim cb As OleDbCommandBui lder = New
OleDbCommandBui lder(PatientsBi llingDataAdapte r)

‘Updating dataset ……….
myDataAdapter.U pdate(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 OleDbCommandBui lder GetUpdateComman d.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 OleDbCommandBui lder.
Here is a code I am using

myDataAdapter = New OleDbDataAdapte r
myDataAdapter.S electCommand = New OleDbCommand("S elect * from [Patient
Table]", MyConnection)
Dim cb As OleDbCommandBui lder = New
OleDbCommandBui lder(PatientsBi llingDataAdapte r)

‘Updating dataset ……….
myDataAdapter.U pdate(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.Fil l 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.Fil l, 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.Exe cuteNonQuery. 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.Exe cuteNonQuery 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 OleDbCommandBui lder.
Here is a code I am using

myDataAdapter = New OleDbDataAdapte r
myDataAdapter.S electCommand = New OleDbCommand("S elect * from [Patient
Table]", MyConnection)
Dim cb As OleDbCommandBui lder = New
OleDbCommandBui lder(PatientsBi llingDataAdapte r)

‘Updating dataset ……….
myDataAdapter.U pdate(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.Fil l 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.Fil l, 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.Exe cuteNonQuery. 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.Exe cuteNonQuery 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 OleDbCommandBui lder.
Here is a code I am using

myDataAdapter = New OleDbDataAdapte r
myDataAdapter.S electCommand = New OleDbCommand("S elect * from [Patient
Table]", MyConnection)
Dim cb As OleDbCommandBui lder = New
OleDbCommandBui lder(PatientsBi llingDataAdapte r)

‘Updating dataset ……….
myDataAdapter.U pdate(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
3741
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 appreciated.. Error: An unhandled exception of type "System.Data.OleDb.OleDbException' occurred in system.data.dll This error is from the following line:
2
3824
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? public void CopyDataSet(int start, int end) { OleDbDataAdapter sourceAdapter = new OleDbDataAdapter("SELECT * FROM " + "WHERE ID > " + (start - 1).ToString() + " AND .id < " + (end + 1).ToString(), connectionString
1
5097
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: dsLocalDataSet.user_postRow newRow = dsLocalDataSet1.user_post.Newuser_postRow(); newRow.post_text = this.lblHiddenMessageStorage.Text; newRow.post_datetime = System.DateTime.Now; dsLocalDataSet1.user_post.Adduser_postRow(newRow);...
9
5283
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 INTO Table ( ID, Cod, CodArt, Q1, DataUscita ) VALUES (pID, pCod, pCod, pQ1, pDataUscita);
0
5832
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 which indexes computer magazine articles for personal reference. I am developing a Visual Basic.NET program whose sole purpose is to enter new records into the database. No updates to existing entries, no deletions, and no display
1
4801
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 the field ends up with only a date, with no time component. In my project... I added an OleDBDataAdapter using the wizzard to my form. I generated the DataSet and added the desired table. I verified the field type in the
6
1869
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 insert statement in the two adapters, the adapter created with the wizard works fine, but the adapter created in code gives me an error "Object reference not set to an instance of an object". The code is below. What am I doing wrong? ...
2
2937
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 draging Table1 to Form2. The select command works fine, but when I change the data and call update command I get a syntax error: System.Data.OleDb.OleDbException was unhandled ErrorCode=-2147217900 Message="Syntax error in UPDATE statement."...
6
1684
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 also created oledb connections to both data sources. Below is my attempt at achieving this, which doesn't work. I've
0
9842
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9682
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10566
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10623
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9398
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7000
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5848
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4474
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4040
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.