PC Review Forums Newsgroups Microsoft DotNet Microsoft ADO .NET SQL Error? Incorrect Syntax near '1'

Reply

SQL Error? Incorrect Syntax near '1'

 
Thread Tools Rate Thread
Old 14-09-2006, 01:11 AM   #1
=?Utf-8?B?R3JlZyBQLg==?=
Guest
 
Posts: n/a
Default SQL Error? Incorrect Syntax near '1'


I have created an insert statement by concatenation in VS2005 going to
SQLServer 2005. If i copy the string out of my watch window and run it as a
query on my Database it works fine. If I do an execute non-query on it I the
the above error.

I have adjusted the syntax by removing all of the variables I was using and
I still get the same error. I added constants (never using a #1) and still
get the same error. The code is as follows. I blow up on line ExecuteSQL =
cmdExecuteSQL.ExecuteNonQuery(). So the connection opens, the command is
assigned correctly so it must be the string right? Wrong the string works
fine in a Query in Sql Server 05. I have no idea what the problem is?

Dim strSql as string = ...
Dim strCnn As String = My.Settings.csStrategy.ToString
Dim CnnStrat As SqlConnection = New SqlConnection(strCnn)
Try
CnnStrat.Open()
Dim cmdExecuteSQL As SqlCommand = New SqlCommand(strSql, CnnStrat)
cmdExecuteSQL.CommandText = CommandType.Text

ExecuteSQL = cmdExecuteSQL.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.ToString)
Finally
CnnStrat.Close()
End Try

Thanks,
  Reply With Quote
Old 14-09-2006, 01:37 AM   #2
=?Utf-8?B?R3JlZyBQLg==?=
Guest
 
Posts: n/a
Default RE: SQL Error? Incorrect Syntax near '1'

I now created a test table with one field and tried to insert a 0 into the
field and I got the same error. A basic "Insert into testTable (code) Values
(0)" caused the same error. This doens't seem like a sql syntax issue but
I've been wrong before.... Any ideas?

Thanks,

"Greg P." wrote:

> I have created an insert statement by concatenation in VS2005 going to
> SQLServer 2005. If i copy the string out of my watch window and run it as a
> query on my Database it works fine. If I do an execute non-query on it I the
> the above error.
>
> I have adjusted the syntax by removing all of the variables I was using and
> I still get the same error. I added constants (never using a #1) and still
> get the same error. The code is as follows. I blow up on line ExecuteSQL =
> cmdExecuteSQL.ExecuteNonQuery(). So the connection opens, the command is
> assigned correctly so it must be the string right? Wrong the string works
> fine in a Query in Sql Server 05. I have no idea what the problem is?
>
> Dim strSql as string = ...
> Dim strCnn As String = My.Settings.csStrategy.ToString
> Dim CnnStrat As SqlConnection = New SqlConnection(strCnn)
> Try
> CnnStrat.Open()
> Dim cmdExecuteSQL As SqlCommand = New SqlCommand(strSql, CnnStrat)
> cmdExecuteSQL.CommandText = CommandType.Text
>
> ExecuteSQL = cmdExecuteSQL.ExecuteNonQuery()
> Catch ex As Exception
> MsgBox(ex.ToString)
> Finally
> CnnStrat.Close()
> End Try
>
> Thanks,

  Reply With Quote
Reply



Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off