473,657 Members | 2,474 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

INSERT syntax error

when I try to write to a database I get a syntax error
I made the code a simple as possible bur also the VS generated code
gives the same error. WHY?
private void button1_Click(o bject sender, System.EventArg s e)
{
string strSQL;
strSQL = "INSERT INTO Overwerk(datum , begin, eind, omschrijving)
VALUES('10-01-2004', '12:00', '16:00', 'Test')";

string strDSN = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=\\data\\ Uren.MDB";
OleDbConnection oleDbConnUren = new OleDbConnection (strDSN);
OleDbCommand myCmd = new OleDbCommand( strSQL, oleDbConnUren );
try
{
oleDbConnUren.O pen();
myCmd.ExecuteNo nQuery();
}
catch (Exception ex)
{
Console.WriteLi ne("Error:\n{0} ", ex.Message);
}
finally
{
oleDbConnUren.C lose();
}

}
Nov 16 '05 #1
5 2000
Berend,

1. Where do you get the error, trying to open the connection or executing
the query?

2. Can you execute the query successfully in a microsoft access query
window?
<Berend> wrote in message news:N7******** *************** ***@4ax.com...
when I try to write to a database I get a syntax error
I made the code a simple as possible bur also the VS generated code
gives the same error. WHY?
private void button1_Click(o bject sender, System.EventArg s e)
{
string strSQL;
strSQL = "INSERT INTO Overwerk(datum , begin, eind, omschrijving)
VALUES('10-01-2004', '12:00', '16:00', 'Test')";

string strDSN = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=\\data\\ Uren.MDB";
OleDbConnection oleDbConnUren = new OleDbConnection (strDSN);
OleDbCommand myCmd = new OleDbCommand( strSQL, oleDbConnUren );
try
{
oleDbConnUren.O pen();
myCmd.ExecuteNo nQuery();
}
catch (Exception ex)
{
Console.WriteLi ne("Error:\n{0} ", ex.Message);
}
finally
{
oleDbConnUren.C lose();
}

}

Nov 16 '05 #2
Is this the actual code? If you are getting a syntax error the likely
causes are you are using a Reserved word (from Access in the field name
http://www.knowdotnet.com/articles/reservedwords.html) or you have an
apostrophe somehwere in there.

Put a breakpoint right before the executenonquery and lets see exactly
what's blowing up, the most likely causes are one of the two and since you
mention this isn't thequery used, it's the most likely.

HTH,

Bill
www.devbuzz.com
www.knowdotnet.com

<Berend> wrote in message news:N7******** *************** ***@4ax.com...
when I try to write to a database I get a syntax error
I made the code a simple as possible bur also the VS generated code
gives the same error. WHY?
private void button1_Click(o bject sender, System.EventArg s e)
{
string strSQL;
strSQL = "INSERT INTO Overwerk(datum , begin, eind, omschrijving)
VALUES('10-01-2004', '12:00', '16:00', 'Test')";

string strDSN = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=\\data\\ Uren.MDB";
OleDbConnection oleDbConnUren = new OleDbConnection (strDSN);
OleDbCommand myCmd = new OleDbCommand( strSQL, oleDbConnUren );
try
{
oleDbConnUren.O pen();
myCmd.ExecuteNo nQuery();
}
catch (Exception ex)
{
Console.WriteLi ne("Error:\n{0} ", ex.Message);
}
finally
{
oleDbConnUren.C lose();
}

}

Nov 16 '05 #3
William and Ben thanks for your quick respond

Adding brackets to the field names solved the problem
I wil look for the reserved word an change him

Berend
On Mon, 10 May 2004 14:13:01 -0400, "William Ryan eMVP"
<do********@com cast.nospam.net > wrote:
Is this the actual code? If you are getting a syntax error the likely
causes are you are using a Reserved word (from Access in the field name
http://www.knowdotnet.com/articles/reservedwords.html) or you have an
apostrophe somehwere in there.

Put a breakpoint right before the executenonquery and lets see exactly
what's blowing up, the most likely causes are one of the two and since you
mention this isn't thequery used, it's the most likely.

HTH,

Bill
www.devbuzz.com
www.knowdotnet.com

<Berend> wrote in message news:N7******** *************** ***@4ax.com...
when I try to write to a database I get a syntax error
I made the code a simple as possible bur also the VS generated code
gives the same error. WHY?
private void button1_Click(o bject sender, System.EventArg s e)
{
string strSQL;
strSQL = "INSERT INTO Overwerk(datum , begin, eind, omschrijving)
VALUES('10-01-2004', '12:00', '16:00', 'Test')";

string strDSN = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=\\data\\ Uren.MDB";
OleDbConnection oleDbConnUren = new OleDbConnection (strDSN);
OleDbCommand myCmd = new OleDbCommand( strSQL, oleDbConnUren );
try
{
oleDbConnUren.O pen();
myCmd.ExecuteNo nQuery();
}
catch (Exception ex)
{
Console.WriteLi ne("Error:\n{0} ", ex.Message);
}
finally
{
oleDbConnUren.C lose();
}

}


Nov 16 '05 #4
Glad it worked.

Cheers,

Bill

www.devbuzz.com
www.knowdotnet.com

<Berend> wrote in message news:es******** *************** ***@4ax.com...
William and Ben thanks for your quick respond

Adding brackets to the field names solved the problem
I wil look for the reserved word an change him

Berend
On Mon, 10 May 2004 14:13:01 -0400, "William Ryan eMVP"
<do********@com cast.nospam.net > wrote:
Is this the actual code? If you are getting a syntax error the likely
causes are you are using a Reserved word (from Access in the field name
http://www.knowdotnet.com/articles/reservedwords.html) or you have an
apostrophe somehwere in there.

Put a breakpoint right before the executenonquery and lets see exactly
what's blowing up, the most likely causes are one of the two and since youmention this isn't thequery used, it's the most likely.

HTH,

Bill
www.devbuzz.com
www.knowdotnet.com

<Berend> wrote in message news:N7******** *************** ***@4ax.com...
when I try to write to a database I get a syntax error
I made the code a simple as possible bur also the VS generated code
gives the same error. WHY?
private void button1_Click(o bject sender, System.EventArg s e)
{
string strSQL;
strSQL = "INSERT INTO Overwerk(datum , begin, eind, omschrijving)
VALUES('10-01-2004', '12:00', '16:00', 'Test')";

string strDSN = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=\\data\\ Uren.MDB";
OleDbConnection oleDbConnUren = new OleDbConnection (strDSN);
OleDbCommand myCmd = new OleDbCommand( strSQL, oleDbConnUren );
try
{
oleDbConnUren.O pen();
myCmd.ExecuteNo nQuery();
}
catch (Exception ex)
{
Console.WriteLi ne("Error:\n{0} ", ex.Message);
}
finally
{
oleDbConnUren.C lose();
}

}

Nov 16 '05 #5
Berend <> wrote in news:N7******** *************** ***@4ax.com:
when I try to write to a database I get a syntax error
I made the code a simple as possible bur also the VS generated code
gives the same error. WHY?
private void button1_Click(o bject sender, System.EventArg s e)
{
string strSQL;
strSQL = "INSERT INTO Overwerk(datum , begin, eind, omschrijving)
VALUES('10-01-2004', '12:00', '16:00', 'Test')";

string strDSN = "Provider=Micro soft.Jet.OLEDB. 4.0;Data
Source=\\data\\ Uren.MDB";


doesn't the date have to be surrounded by ## instead of '' when working
with Access?

#10-01-2004# or maybe #10/01/2004#
--
Joris "flotspe" Janssens
http://www.xhtml.be/inferno/
Don't wait for the Grim Reaper,
I'm going to mow you down!
Nov 16 '05 #6

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

Similar topics

15
7379
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great atmosphere. Good food.", " (Harry Houdini - 03/01/2004)"); INSERT INTO `reviews` VALUES("", "Le Chow Place", "Lunch", "yada yada", " (Herbert Hoover - 03/03/2004)"); INSERT INTO `reviews` VALUES("", "Golden Dragon", "Lunch", "Exquisite.
24
22613
by: deko | last post by:
I'm trying to log error messages and sometimes (no telling when or where) the message contains a string with double quotes. Is there a way get the query to insert the string with the double quotes? Do I need to use code to scrub each string and remove or escape the double quotes before using it in a query? The error I get is this: Error Number 3075: Syntax error (missing operator) in query expression '"credit card billed by...
7
6659
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double checked, and the insert works fine (tried to use it from access)... im using visual C# express 2k5... what could be wrong? thanks!
2
5730
by: Bob Alston | last post by:
I am going blind tonight but I cannot figure out the error. I get a syntax error from this sql statement, being run via vba in access 2003 insert into tbl_Volunteer_Donor in "C:\AgencySystemVer1.32.mdb" ( ,,,,,,,,,,,,,,,,,,,) select (,,,,,,,,,,,,,,,,,,,) from tbl_Volunteer_Donor in "C:\SapulpaCommunity Care NEW.mdb"; I am trying to copy the exact same fields (but not all the available
3
2305
by: MP | last post by:
Hi Posted this several hours ago to another ng but it never showed up thought i'd try here. using vb6, ado, .mdb, jet4.0, no access given table tblJob with field JobNumber text(10) 'The example I had to go by 'INSERT INTO tblCustomers (CustomerID, , )
2
8255
by: speralta | last post by:
My tired old eyes may be failing me, but the following insert statements look correct to me, but I can't seem to get a clean insert from a fairly large text file database into mysql. I was wondering if maybe I'm hitting a limit on character length per line on some insert statements that I'm trying. Here's the error messages: execute failed: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server...
5
4828
by: mabond | last post by:
Hi VB.NET 2005 Express edition Microsoft Access 2000 (SP-3) Having trouble writing an "insert into" command for a Microsoft table I'm accessing through oledb. I've tried to follow the same principle I'd use if it was an sql database but I'm getting an error telling me the syntax of the "insert into" command
2
4802
by: technocraze | last post by:
Hi guys, I have encountered this error when updating the values to the MS Acess table. Error : Update on linked table failed. ODBC sql server error Timeout expired. MS Acess is my front end and sql server is my backend server. This error occured whenever i step through and when it reaches rs.update it jux hangs down there and thereafter it shwn the aforementioned error. I am using the RecordSet properties to add the values. Can I use...
6
3450
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am using MS-Access 2000 database table for this app. Note that the datatype of all the fields mentioned above are Text. Apart from the above columns, there's another column in the DB table named 'RegDateTime' whose datatype is Date/Time which is...
2
7034
josie23
by: josie23 | last post by:
Egad, I'm not a coder/programmer by nature or occupation but understand things like html and css and a small amount of perl. So, basically, I'm a perl/mysql imbecile. But, I've been trying to find syntax to insert values into a mysql database table. I'm able to use the below syntax to insert hard-coded values like 'josie' and 'smith' but can't find working syntax to insert $scalar data from another file (which is really what perl-mysql is...
0
8413
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, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7352
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, and deployment—without 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...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5642
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
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2742
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
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.