473,394 Members | 1,821 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,394 software developers and data experts.

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(object sender, System.EventArgs e)
{
string strSQL;
strSQL = "INSERT INTO Overwerk(datum , begin, eind, omschrijving)
VALUES('10-01-2004', '12:00', '16:00', 'Test')";

string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\\data\\Uren.MDB";
OleDbConnection oleDbConnUren = new OleDbConnection(strDSN);
OleDbCommand myCmd = new OleDbCommand( strSQL, oleDbConnUren );
try
{
oleDbConnUren.Open();
myCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine("Error:\n{0}", ex.Message);
}
finally
{
oleDbConnUren.Close();
}

}
Nov 16 '05 #1
5 1991
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(object sender, System.EventArgs e)
{
string strSQL;
strSQL = "INSERT INTO Overwerk(datum , begin, eind, omschrijving)
VALUES('10-01-2004', '12:00', '16:00', 'Test')";

string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\\data\\Uren.MDB";
OleDbConnection oleDbConnUren = new OleDbConnection(strDSN);
OleDbCommand myCmd = new OleDbCommand( strSQL, oleDbConnUren );
try
{
oleDbConnUren.Open();
myCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine("Error:\n{0}", ex.Message);
}
finally
{
oleDbConnUren.Close();
}

}

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(object sender, System.EventArgs e)
{
string strSQL;
strSQL = "INSERT INTO Overwerk(datum , begin, eind, omschrijving)
VALUES('10-01-2004', '12:00', '16:00', 'Test')";

string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\\data\\Uren.MDB";
OleDbConnection oleDbConnUren = new OleDbConnection(strDSN);
OleDbCommand myCmd = new OleDbCommand( strSQL, oleDbConnUren );
try
{
oleDbConnUren.Open();
myCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine("Error:\n{0}", ex.Message);
}
finally
{
oleDbConnUren.Close();
}

}

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********@comcast.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(object sender, System.EventArgs e)
{
string strSQL;
strSQL = "INSERT INTO Overwerk(datum , begin, eind, omschrijving)
VALUES('10-01-2004', '12:00', '16:00', 'Test')";

string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\\data\\Uren.MDB";
OleDbConnection oleDbConnUren = new OleDbConnection(strDSN);
OleDbCommand myCmd = new OleDbCommand( strSQL, oleDbConnUren );
try
{
oleDbConnUren.Open();
myCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine("Error:\n{0}", ex.Message);
}
finally
{
oleDbConnUren.Close();
}

}


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********@comcast.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(object sender, System.EventArgs e)
{
string strSQL;
strSQL = "INSERT INTO Overwerk(datum , begin, eind, omschrijving)
VALUES('10-01-2004', '12:00', '16:00', 'Test')";

string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=\\data\\Uren.MDB";
OleDbConnection oleDbConnUren = new OleDbConnection(strDSN);
OleDbCommand myCmd = new OleDbCommand( strSQL, oleDbConnUren );
try
{
oleDbConnUren.Open();
myCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine("Error:\n{0}", ex.Message);
}
finally
{
oleDbConnUren.Close();
}

}

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(object sender, System.EventArgs e)
{
string strSQL;
strSQL = "INSERT INTO Overwerk(datum , begin, eind, omschrijving)
VALUES('10-01-2004', '12:00', '16:00', 'Test')";

string strDSN = "Provider=Microsoft.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
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...
24
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...
7
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...
2
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...
3
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...
2
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...
5
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...
2
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...
6
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...
2
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
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...

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.