SQL Error? Incorrect Syntax near '1'

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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,
 
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,
 
Back
Top