Inserting new row with OleDb

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

Ok
thanks for the reply
I have checked that, still same error. I will paste my
Insert statement.

"INSERT INTO AddressBook(FirstNames, Surname, Address,
Company, TelHome, TelWork, TelFax, TelMobile,
PostalAddress, Position) VALUES
('test', 'test', 'test', 'test', 'test', 'test', 'test', 't
est', 'test', 'test')"

all fields are of type TEXT and there is an "ID" field of
type "AutoNumber"

i have also tried

"INSERT INTO AddressBook(FirstNames, Surname, Address,
Company, TelHome, TelWork, TelFax, TelMobile,
PostalAddress, Position) VALUES (test, test, test, test,
test, test, test, test, test, test)"

this also did not work.
the OleDbCommandBuilder generates this command

"INSERT INTO AddressBook(FirstNames, Surname, Address,
Company, TelHome, TelWork, TelFax, TelMobile,
PostalAddress, Position) VALUES
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"

which also does not work.

all 3 statements apparently have a syntax error. I get
a "Syntax error in INSERT INTO statement". maybe
someone could spot it, or perhaps the problem is not here?

Thanks for the help
Jason
 
Could you please procvide me the table structure definition.

Maybe i will give it a try

Thanks,
Jagan Mohan
 
Here is a test i coded that returns the error "Syntax
error in INSERT INTO statement"

string strConnStr
= "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=D:\\JASON\\PROJECTS\\SAMPLE\\WINDOWS\\DATAACCESS\\Ad
dressBook.mdb";
OleDbConnection oledbconn
= new OleDbConnection(strConnStr);
oledbconn.Open();

string insertstr = "INSERT
INTO AddressBook(FirstNames, Surname, Address, Company,
TelHome, TelWork, TelFax, TelMobile, PostalAddress,
Position) VALUES
('test', 'test', 'test', 'test', 'test', 'test', 'test', 't
est', 'test', 'test')";

OleDbCommand insertComm =
new OleDbCommand(insertstr);
insertComm.Connection =
oledbconn;
int x =
insertComm.ExecuteNonQuery();


Please can someone help out...Thanks
Jason
-----Original Message-----
This is a Access Database

ID, FirstNames, Surname, Address, Company, TelHome,
TelWork, TelFax, TelMobile, PostalAddress, Position. These
are all the columns. All except "ID" are of type "Text" -
Field Size 50 (rest on default field settings). "ID" is of
Type "AutoNumber", Long Integer, Increment and Indexed.

Thanks
If this is unclear i can try provide more
('test', 'test', 'test', 'test', 'test', 'test', 'test', 't
 
This worked out for me,

I think Address is a keyword or somewhat, just use [] in your column names
thats all.

string insertstr = "INSERT INTO AddressBook([FirstNames], [Surname],
[Address], [Company], [TelHome], [TelWork], [TelFax], [TelMobile],
[PostalAddress], [Position]) VALUES ('test', 'test', 'test', 'test', 'test',
'test', 'test', 'test', 'test', 'test')";



Thanks,

Jagan Mohan

Software Engineer

Scape Velocity
 
Ack
How annoying, thanks alot! :-)

btw did you also get the same error without the []s?

Jason
-----Original Message-----


This worked out for me,

I think Address is a keyword or somewhat, just use [] in your column names
thats all.

string insertstr = "INSERT INTO AddressBook([FirstNames], [Surname],
[Address], [Company], [TelHome], [TelWork], [TelFax], [TelMobile],
[PostalAddress], [Position]) VALUES
('test', 'test', 'test', 'test', 'test',
 
Thanks for the help again

It isnt Address being the keyword. I changed the
column "Position" to "Positionline" (couldnt think of
anything else :-)) and that worked without having to use
the []s

Jason
-----Original Message-----


This worked out for me,

I think Address is a keyword or somewhat, just use [] in your column names
thats all.

string insertstr = "INSERT INTO AddressBook([FirstNames], [Surname],
[Address], [Company], [TelHome], [TelWork], [TelFax], [TelMobile],
[PostalAddress], [Position]) VALUES
('test', 'test', 'test', 'test', 'test',
 
Back
Top