SQL statement in Access

J

John Sutor

I am trying to write an insert statement in Access but it is not working
with the OleDBCommand object.
HEre is the code

string sqltxt= "INSERT INTO contacts ( Last_Name, First_Name,
Email_Address, [Note] )" +
" WHERE (Last_Name)='Testlast') AND (First_Name)='TestFirst') AND
(Email_Address)='TestEmail') AND (Note)='TestNote')";
Debug.WriteLine(sqltxt);

OleDbConnection myConnection = new OleDbConnection(connectString);
OleDbCommand myCommand = new OleDbCommand(sqltxt, myConnection);
myCommand.Connection.Open();
int ret = myCommand.ExecuteNonQuery()
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

I think that the error is in your query, INSERT INTO ... WHERE .. ??

you are mixing INSERT with UPDATE syntax.

Cheers,
 
G

Gerry O'Brien [MVP]

You don't have a values section in your INSERT statement.

INSERT INTO contacts(Last_Name, First_Name) VALUES(lastname, firstname)
 
J

John Sutor

This did not work.

string sqltxt = "Insert Into contacts (customerid, companyname,
contactname) Values (" + "'" + sLast + "'" + "," + "'" + sFirst + "'" +
"," +
"'" + sEmail + "'" + "," + "'" + sNote + "'" + ")" ;
 
R

Rajagopal Pasupuleti

are you sending correct number of values as parameters check your commas
in the prepared statement write your sqltxt as output and check..
 

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