Incorrect syntax near 'Calculation'.

sql server India
  • 13 years ago

    I am using VS 2005 + SQL Server 2000.

    The piece of code is as follows

         Public Function GetAppId(ByRef AN As String) As String        Dim scon As New System.Data.SqlClient.SqlConnection ‘ declare the connection        scon.ConnectionString = ConfigurationManager.ConnectionStrings("strSimCon").ToString ‘ strSimCon is connection ‘ ‘string  stored in web.config file        scon.Open()’ opening of connection        Dim querystring As String = "Select AppCode From ApplicationData Where AppName=" & AN ‘ AN is the ‘ string which will contain Name of The application. On the basis of this name a unique ID will be retrieved.        Dim myCommand As New System.Data.SqlClient.SqlCommand(querystring, scon)        Dim sreader As System.Data.SqlClient.SqlDataReader       * sreader = myCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection)’ I have tried using no  option or all other options .But no result.        GetAppId = sreader.GetString(0)        Return GetAppId

        End Function

     

    I am getting an error (exception) as System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near 'Calculation'.  Can anyone guide me what is not correct? 
  • 13 years ago

    If "AN" is a string value then your code should read:

    querystring As String = "Select AppCode From ApplicationData Where AppName='" & AN & "'"

    ie you are forgetting to wrap the string value in sql quotes.

    Hope this helps

    Joe
     

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Memory is like an orgasm. It's a lot better if you don't have to fake it.” - Seymour Cray