Problem updating a database :(

S

SteMc

I have a slight problem updating a table in a database (vb.net)

my code looks like the following

Dim new_row As DataRow = {datatable}.NewRow
..
..
..
//the following are the only columns in my table//
line 1: new_row("coming_from") = "1000"
line 2: new_row("text") = "blah blah blah"
line 3: new_row("going_to") = "-1"
line 4: new_row("solution") = true
line 5: new_row("q_a_s") = "answer"

line 6: {data_table}.Rows.Add(new_row)

line 7: {data_adapter}.Update(data_table)***

This is where I am having a problem (Line 7). My database has about 5
tables and all of them have been updated in some fashion, all in this
exact manner and have worked perfectly - but this one won't.

I've checked the datatable in the command window after line 6 has
completed and the new row has been added and all the data is correct.
However when the prog reaches line 7 it gives the following error
message:

"An unhandled exception of type 'System.Data.OleDb.OleDbException'
occurred in System.data.dll"

When I use the command window and type in "?
{data_adapter}.Update(data_table)" I get the following message:

"Run-time exception thrown : System.Data.OleDb.OleDbException - Syntax
error in INSERT INTO statement."

What this means I just do not know and am hoping that somebody here can
help me?

As I've used the same method of code as when trying to update other
tables I assumed it should work but it just doesn't want to :(

thanks,

Steve
 
A

Armin Zingler

SteMc said:
//the following are the only columns in my table//
line 1: new_row("coming_from") = "1000"
line 2: new_row("text") = "blah blah blah"

[...]

"Run-time exception thrown : System.Data.OleDb.OleDbException -
Syntax
error in INSERT INTO statement."

What this means I just do not know and am hoping that somebody here
can
help me?



It means that you didn't enclose the field name "text" in square brackets:

insert into bla (coming_from, [text], ....) values (...)


If you use a Commandbuilder, set it's quoteprefix and quotesuffix properties
to "[" and "]".


Armin
 
G

Guest

Steve,

I wonder if one of your column names, perhaps "text", is a reserved word and
must therefore be placed inside square brackets: [text], for example.

Kerry Moorman
 
S

SteMc

Briliant! I tried changing the column heading from "text" to
"desired_text" and it worked perfectly.

I've encountered a few problems with the database but I didn't even
consider the problem of reserved words, good stuff :)

thank you both for your help,

Steve
 
J

Joergen Bech

Briliant! I tried changing the column heading from "text" to
"desired_text" and it worked perfectly.

I've encountered a few problems with the database but I didn't even
consider the problem of reserved words, good stuff :)

thank you both for your help,

Steve

For future reference: SQL Server, ODBC, and future keywords:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ra-rz_9oj7.asp

Add to that the data types (including "text").

Merging those lists with similar lists for Oracle, MySQL, Access, etc.
should help prevent problems in the future if the system should ever
support those as well.

Note: QuotePrefix/QuoteSuffix are new in .Net 2.0, hence not available
in 2002/2003 (version was not specified).

/JB
 
G

Guest

Joergen Bech said:
For future reference: SQL Server, ODBC, and future keywords:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_ra-rz_9oj7.asp

Add to that the data types (including "text").

Merging those lists with similar lists for Oracle, MySQL, Access, etc.
should help prevent problems in the future if the system should ever
support those as well.

Note: QuotePrefix/QuoteSuffix are new in .Net 2.0, hence not available
in 2002/2003 (version was not specified).

/JB

Also if you ran the query in Query Analyzer it would have told you the
issue.

Chirs
 

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

Similar Threads

Help with simple query 3
Database Saving 1
Need Help adding database records 8
Find & Replace Problem 2
Very Simple Problem 5
SqlTransaction 3
Simple (?) DB Connection problem 3
Windows 7 dll import problem 26

Top