Re: INSERT command doesn't work in Access
- From: "MW" <crul@xxxxxxxxxxxxxx>
- Date: Wed, 15 Jun 2005 16:07:21 +0200
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
>>
>
>
.
- Follow-Ups:
- Re: INSERT command doesn't work in Access
- From: W.G. Ryan eMVP
- Re: INSERT command doesn't work in Access
- From: Rogas69
- Re: INSERT command doesn't work in Access
- References:
- INSERT command doesn't work in Access
- From: MW
- Re: INSERT command doesn't work in Access
- From: W.G. Ryan eMVP
- INSERT command doesn't work in Access
- Prev by Date: Re: How to check if filled ?
- Next by Date: Re: INSERT command doesn't work in Access
- Previous by thread: Re: INSERT command doesn't work in Access
- Next by thread: Re: INSERT command doesn't work in Access
- Index(es):
Relevant Pages
|