problem with insert into

B

belange

I have this line of code : string insert = @"INSERT INTO Reservation
(StudentName, Day, Hour, Station) Values('julien', '8 july 20004', '12.00
pm', 'station 1')";

but when I run the web form, I have this error

Exception Details: System.Data.OleDb.OleDbException: Syntax error in INSERT
INTO statement.

Source Error:

Line 106: commandReserv = new OleDbCommand(insert,connectReserv);
Line 107: connectReserv.Open();
Line 108: commandReserv.ExecuteNonQuery();
Line 109: connectReserv.Close();
Line 110: connectReserv.Dispose();


Can you help me because I do not find the mistake, Thanks for your help.
 
K

Kevin Spencer

Hard to say for sure. I would suspect that at least some of your column
names ("Day" and "Hour" stick out to me) are reserved words in the database
product you're using. However, I don't know WHAT database product you're
using, so I can't advise you as to how to handle it. Different databases use
different rules. In any Microsoft database, putting [square brackets] around
the column names would do the trick.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
B

belange

Kevin Spencer said:
Hard to say for sure. I would suspect that at least some of your column
names ("Day" and "Hour" stick out to me) are reserved words in the database
product you're using. However, I don't know WHAT database product you're
using, so I can't advise you as to how to handle it. Different databases use
different rules. In any Microsoft database, putting [square brackets] around
the column names would do the trick.
Thanks Kevin for your answer, I use an access database.
 
S

spalding

put square brackets around your Day and Hour fields

eg.

INSERT INTO Reservation(StudentName, [Day], [Hour], Station) VALUES
('Julien', '8 july 2004', '12pm', 'Station 1');
 

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

Top