Re: INSERT command doesn't work in Access

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hey,

This is the previous version of the code that also doesn't work. I get with
that OleDbException, that says "Syntax error in SQL statement". Any ideas?

this.databaseConnection.Open();


this.insertDataTableCommand.Connection = this.databaseConnection;

this.insertDataTableCommand.CommandText = "INSERT INTO DataTable(ContactID,
Date) VALUES (@ContactID, @Date)";



this.insertDataTableCommand.Parameters.Add("@ContactID", OleDbType.VarWChar,
50);

this.insertDataTableCommand.Parameters.Add("@Date", OleDbType.Date);

//now set all parameters properly

this.insertDataTableCommand.Parameters["@ContactID"].Value = "Test";

this.insertDataTableCommand.Parameters["@Date"].Value = DateTime.Now;

this.insertDataTableCommand.ExecuteNonQuery();


this.databaseConnection.Close();




"W.G. Ryan eMVP" <WilliamRyan@xxxxxxxxx> wrote in message
news:uOpW7DbcFHA.1152@xxxxxxxxxxxxxxxxxxxxxxx
>I think the problem is the date, you should escape it or better, use
>Parameters. Also, it's probably an OleDbException that's being thrown, if
>you're getting a SqlException, something else must be the culprit.
>
> --
> W.G. Ryan, MVP
>
> www.tibasolutions.com | www.devbuzz.com | www.knowdotnet.com
> "MW" <crul@xxxxxxxxxxxxxx> wrote in message
> news:d8p8mt$lab$1@xxxxxxxxxxxxxxx
>> Hello,
>>
>> I have a problem with calling INSERT command. It throws everytime a SQL
>> exception, even though the syntax is proper. At the begining I've tried
>> using OleDbCommand, and it worked for 2 tables, but it doesn't work for
>> third final one. These are really easy tables, so I'm really shocked it
>> doesn't work. Lately I've tried simple OleDbCommand, but it still doesn't
>> work. Did anyone bump into this problem earlier ?
>>
>> Table has three columns:
>> Name : DataType
>> 1. RowID : AutoNumber
>> 2. ContactID : Text
>> 3. Date : Date/Time
>>
>> The last version of the code, that still generates error is:
>>
>> OleDbCommand comm = new OleDbCommand("INSERT INTO DataTable(ContactID,
>> Date) VALUES(dfsfsdfdf, 3/3/2002)",
>>
>> this.databaseConnection);
>>
>> comm.ExecuteNonQuery();
>>
>>
>> I appreciete any help,
>> Marcin Waligora
>>
>
>


.



Relevant Pages

  • Re: INSERT command doesnt work in Access
    ... doesn't like it b/c it's areserved word. ... that says "Syntax error in SQL statement". ... Lately I've tried simple OleDbCommand, ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Syntax error in FROM clause
    ... It appears that the maximum length of the SQL statement has been reached. ... "George wilson" wrote in message ... >><MS ACCESS MVP> ... >>> a "Syntax error in FROM clause" and is unable to view ...
    (microsoft.public.access.forms)
  • Re: rewrite QBE SQL statement
    ... I am now getting a syntax error that tells me that I am missing an operator ... Is there a way to rewrite this as nested subqueries in such a way ... I am trying to write a SQL statement based on a SQL statement from the ... I am trying to rewrite this into workable SQL that I can pass as string ...
    (microsoft.public.access.modulesdaovba)
  • Re: Syntax error in INSERT INTO statement.
    ... > I got syntax error in INSERT INTO statement. ... Run the page and look at the sql statement in the browser window. ... This email account is my spam trap so I ...
    (microsoft.public.scripting.vbscript)
  • Re: Combo Box Type Mismatch
    ... I suggest taking this SQL into the query builder and checking it there. ... Here is the sql statement: ... > Syntax error in query expression '[SELECT DISTINCTROW ...
    (microsoft.public.access.gettingstarted)