Home All Groups Group Topic Archive Search About

Problem running query in code

Author
15 Jan 2007 8:19 PM
John
Hi

I am using the below code to run a sql  on an underlying access table;

insStr = "INSERT INTO [Web Site Action Queue] ( Action, [Client ID],
[Operator], Request_Date ) " & _
"VALUES (""Modify Client"", 93, ""Administrator"", Now())"

Dim insCmd As New OleDbCommand(insStr, dbConContacts)

insCmd.ExecuteNonQuery()

I get a 'Syntax error in INSERT INTO statement.' error on the last line.

But if I run the same query as below directly in access it works fine.

INSERT INTO [Web Site Action Queue] ( Action, [Client ID], [Operator],
Request_Date ) VALUES ("Modify Client", 93, "Administrator", Now())

What is the problem and how can I fix it?

Thanks

Regards

Author
15 Jan 2007 8:48 PM
Van T. Dinh
I think the problem is Now() is a VBA function and this is available in JET
only if you are running the Query in Access (via the Expression Service).

From the newsgroups you posted to, I guess you are running this in VB.Net
and I don't think JET would recognize the Now() used in your SQL.

Try with a literal date/time value and see if Now() is the cause.

Perhaps, the VB.Net experts can advise you of an alternative.

--
HTH
Van T. Dinh
MVP (Access)



Show quote
"John" <John@nospam.infovis.co.uk> wrote in message
news:OtvMnJOOHHA.2232@TK2MSFTNGP02.phx.gbl...
> Hi
>
> I am using the below code to run a sql  on an underlying access table;
>
> insStr = "INSERT INTO [Web Site Action Queue] ( Action, [Client ID],
> [Operator], Request_Date ) " & _
> "VALUES (""Modify Client"", 93, ""Administrator"", Now())"
>
> Dim insCmd As New OleDbCommand(insStr, dbConContacts)
>
> insCmd.ExecuteNonQuery()
>
> I get a 'Syntax error in INSERT INTO statement.' error on the last line.
>
> But if I run the same query as below directly in access it works fine.
>
> INSERT INTO [Web Site Action Queue] ( Action, [Client ID], [Operator],
> Request_Date ) VALUES ("Modify Client", 93, "Administrator", Now())
>
> What is the problem and how can I fix it?
>
> Thanks
>
> Regards
>
Author
15 Jan 2007 9:00 PM
John
Tried following, still no luck.

INSERT INTO [Web Site Action Queue] ( Action, [Client ID], [Operator],
Request_Date ) VALUES ("Modify Client", 93, "Administrator", "15/01/2007
20:57:54")

Works in Access but not from in vb.net ExecuteNonQuery().

Thanks

Regards

Show quote
"Van T. Dinh" <VanThien.D***@discussions.microsoft.com> wrote in message
news:O1NDrZOOHHA.4992@TK2MSFTNGP04.phx.gbl...
>I think the problem is Now() is a VBA function and this is available in JET
>only if you are running the Query in Access (via the Expression Service).
>
> From the newsgroups you posted to, I guess you are running this in VB.Net
> and I don't think JET would recognize the Now() used in your SQL.
>
> Try with a literal date/time value and see if Now() is the cause.
>
> Perhaps, the VB.Net experts can advise you of an alternative.
>
> --
> HTH
> Van T. Dinh
> MVP (Access)
>
>
>
> "John" <John@nospam.infovis.co.uk> wrote in message
> news:OtvMnJOOHHA.2232@TK2MSFTNGP02.phx.gbl...
>> Hi
>>
>> I am using the below code to run a sql  on an underlying access table;
>>
>> insStr = "INSERT INTO [Web Site Action Queue] ( Action, [Client ID],
>> [Operator], Request_Date ) " & _
>> "VALUES (""Modify Client"", 93, ""Administrator"", Now())"
>>
>> Dim insCmd As New OleDbCommand(insStr, dbConContacts)
>>
>> insCmd.ExecuteNonQuery()
>>
>> I get a 'Syntax error in INSERT INTO statement.' error on the last line.
>>
>> But if I run the same query as below directly in access it works fine.
>>
>> INSERT INTO [Web Site Action Queue] ( Action, [Client ID], [Operator],
>> Request_Date ) VALUES ("Modify Client", 93, "Administrator", Now())
>>
>> What is the problem and how can I fix it?
>>
>> Thanks
>>
>> Regards
>>
>
>
Author
15 Jan 2007 9:34 PM
Van T. Dinh
Date literal in JET must be of the US format "mm/dd/yyyy hh:nn:ss" (or an
unambiguous format like "yyyy-mm-dd hh:nn:ss") and enclosed in hashes (#),
not double-quotes.  Try:

INSERT INTO [Web Site Action Queue]
( [Action], [Client ID], [Operator], [Request_Date] )
VALUES
("Modify Client", 93, "Administrator", #01/15/2005 20:57:54#)

   --
HTH
Van T. Dinh
MVP (Access)



Show quote
"John" <John@nospam.infovis.co.uk> wrote in message
news:ukqCugOOHHA.5000@TK2MSFTNGP03.phx.gbl...
> Tried following, still no luck.
>
> INSERT INTO [Web Site Action Queue] ( Action, [Client ID], [Operator],
> Request_Date ) VALUES ("Modify Client", 93, "Administrator", "15/01/2007
> 20:57:54")
>
> Works in Access but not from in vb.net ExecuteNonQuery().
>
> Thanks
>
> Regards
>
> "Van T. Dinh" <VanThien.D***@discussions.microsoft.com> wrote in message
> news:O1NDrZOOHHA.4992@TK2MSFTNGP04.phx.gbl...
>>I think the problem is Now() is a VBA function and this is available in
>>JET only if you are running the Query in Access (via the Expression
>>Service).
>>
>> From the newsgroups you posted to, I guess you are running this in VB.Net
>> and I don't think JET would recognize the Now() used in your SQL.
>>
>> Try with a literal date/time value and see if Now() is the cause.
>>
>> Perhaps, the VB.Net experts can advise you of an alternative.
>>
>> --
>> HTH
>> Van T. Dinh
>> MVP (Access)
>>
>>
>>
>> "John" <John@nospam.infovis.co.uk> wrote in message
>> news:OtvMnJOOHHA.2232@TK2MSFTNGP02.phx.gbl...
>>> Hi
>>>
>>> I am using the below code to run a sql  on an underlying access table;
>>>
>>> insStr = "INSERT INTO [Web Site Action Queue] ( Action, [Client ID],
>>> [Operator], Request_Date ) " & _
>>> "VALUES (""Modify Client"", 93, ""Administrator"", Now())"
>>>
>>> Dim insCmd As New OleDbCommand(insStr, dbConContacts)
>>>
>>> insCmd.ExecuteNonQuery()
>>>
>>> I get a 'Syntax error in INSERT INTO statement.' error on the last line.
>>>
>>> But if I run the same query as below directly in access it works fine.
>>>
>>> INSERT INTO [Web Site Action Queue] ( Action, [Client ID], [Operator],
>>> Request_Date ) VALUES ("Modify Client", 93, "Administrator", Now())
>>>
>>> What is the problem and how can I fix it?
>>>
>>> Thanks
>>>
>>> Regards
>>>
>>
>>
>
>
Author
4 Mar 2007 11:52 AM
René_Jensen
Could it have something to do with your string notation you use " to
tell that it is a string try with ' instead.

René

John wrote:
Show quote
> Hi
>
> I am using the below code to run a sql  on an underlying access table;
>
> insStr = "INSERT INTO [Web Site Action Queue] ( Action, [Client ID],
> [Operator], Request_Date ) " & _
> "VALUES (""Modify Client"", 93, ""Administrator"", Now())"
>
> Dim insCmd As New OleDbCommand(insStr, dbConContacts)
>
> insCmd.ExecuteNonQuery()
>
> I get a 'Syntax error in INSERT INTO statement.' error on the last line.
>
> But if I run the same query as below directly in access it works fine.
>
> INSERT INTO [Web Site Action Queue] ( Action, [Client ID], [Operator],
> Request_Date ) VALUES ("Modify Client", 93, "Administrator", Now())
>
> What is the problem and how can I fix it?
>
> Thanks
>
> Regards
>
>
Author
4 Mar 2007 2:51 PM
John Spencer
My guess is that NOW() is causing the problem. It is probably not
understood by the database engine.  Try inserting the date and time as a
literal value using # (or perhaps ') as the delimiter.

Something like:

  insStr = "INSERT INTO [Web Site Action Queue] ( Action, [Client ID],
[Operator], Request_Date ) " & _ "VALUES (""Modify Client"", 93,
""Administrator"", #" & Now() & "#)"

This of course assumes that you have NOW as an available function in
your code environment.

'====================================================
  John Spencer
  Access MVP 2002-2005, 2007
  Center for Health Program Development and Management
  University of Maryland Baltimore County
'====================================================


René Jensen wrote:
Show quote
> Could it have something to do with your string notation you use " to
> tell that it is a string try with ' instead.
>
> René
>
> John wrote:
>> Hi
>>
>> I am using the below code to run a sql  on an underlying access table;
>>
>> insStr = "INSERT INTO [Web Site Action Queue] ( Action, [Client ID],
>> [Operator], Request_Date ) " & _
>> "VALUES (""Modify Client"", 93, ""Administrator"", Now())"
>>
>> Dim insCmd As New OleDbCommand(insStr, dbConContacts)
>>
>> insCmd.ExecuteNonQuery()
>>
>> I get a 'Syntax error in INSERT INTO statement.' error on the last line.
>>
>> But if I run the same query as below directly in access it works fine.
>>
>> INSERT INTO [Web Site Action Queue] ( Action, [Client ID], [Operator],
>> Request_Date ) VALUES ("Modify Client", 93, "Administrator", Now())
>>
>> What is the problem and how can I fix it?
>>
>> Thanks
>>
>> Regards
>>
Author
4 Mar 2007 6:03 PM
RobinS
He's using Access, so Now() should work, and he should take out the  #
delimiters.

And use single quotes around 'Modify Client' and 'Administrator'.

Robin S.
---------------------------------------
Show quote
"John Spencer" <spen***@chpdm.umbc> wrote in message
news:eeZ8YymXHHA.3984@TK2MSFTNGP02.phx.gbl...
> My guess is that NOW() is causing the problem. It is probably not
> understood by the database engine.  Try inserting the date and time as a
> literal value using # (or perhaps ') as the delimiter.
>
> Something like:
>
>  insStr = "INSERT INTO [Web Site Action Queue] ( Action, [Client ID],
> [Operator], Request_Date ) " & _ "VALUES (""Modify Client"", 93,
> ""Administrator"", #" & Now() & "#)"
>
> This of course assumes that you have NOW as an available function in your
> code environment.
>
> '====================================================
>  John Spencer
>  Access MVP 2002-2005, 2007
>  Center for Health Program Development and Management
>  University of Maryland Baltimore County
> '====================================================
>
>
> René Jensen wrote:
>> Could it have something to do with your string notation you use " to
>> tell that it is a string try with ' instead.
>>
>> René
>>
>> John wrote:
>>> Hi
>>>
>>> I am using the below code to run a sql  on an underlying access table;
>>>
>>> insStr = "INSERT INTO [Web Site Action Queue] ( Action, [Client ID],
>>> [Operator], Request_Date ) " & _
>>> "VALUES (""Modify Client"", 93, ""Administrator"", Now())"
>>>
>>> Dim insCmd As New OleDbCommand(insStr, dbConContacts)
>>>
>>> insCmd.ExecuteNonQuery()
>>>
>>> I get a 'Syntax error in INSERT INTO statement.' error on the last
>>> line.
>>>
>>> But if I run the same query as below directly in access it works fine.
>>>
>>> INSERT INTO [Web Site Action Queue] ( Action, [Client ID], [Operator],
>>> Request_Date ) VALUES ("Modify Client", 93, "Administrator", Now())
>>>
>>> What is the problem and how can I fix it?
>>>
>>> Thanks
>>>
>>> Regards
>>>

AddThis Social Bookmark Button