Line 1: Incorrect syntax near '='.

Posted on 2005-05-17
Last Modified: 2011-09-20
I think it's something easy to detect but I can't find what's wrong:( Run into this error:

Line 1: Incorrect syntax near '='.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near '='.

Source Error:

Line 438:        Dim objCommand As SqlCommand = New SqlCommand(strSQL, objConn)
Line 439:        objConn.Open()
Line 440:        Dim drPool As SqlDataReader = objCommand.ExecuteReader()     <---IN RED
Line 441:
Line 442:

The function that I was trying to call:

Sub Get_Pro1(ByVal OriginLocation As String)
        Dim strConn1 As String = "Server=RFD1;database=ProNET;uid=prorpt;pwd=prorpt"
        Dim objConn As SqlConnection = New SqlConnection(strConn1)
        Dim strSQL As String = "Select SCACLinehaul, MilesDCToPool, PostalCode from vw_Pool_Locations" _
                                           & "Where SailingDC = OriginLocation"

        Dim objCommand As SqlCommand = New SqlCommand(strSQL, objConn)
        Dim drPool As SqlDataReader = objCommand.ExecuteReader()

        Dim strAddSQL As String = "web_AddSCACLH_MilesDCToPool_PostalCode"
        Dim myCommand As New SqlCommand(strAddSQL, cnConsOrders)

        Dim parmSCACLinehaul As New SqlParameter("@strSCACLH", SqlDbType.Char, 4)
        Dim parmPostalCode As New SqlParameter("@strPostalCode", SqlDbType.VarChar, 9)
        Dim parmMilesDCToPool As New SqlParameter("@strMilesDCToPool", SqlDbType.Int)

        parmSCACLinehaul.Value = drPool("SCACLinehaul")
        parmPostalCode.Value = drPool("PostalCode")
        parmMilesDCToPool.Value = drPool("MilesDCToPool")

        myCommand.CommandType = CommandType.StoredProcedure
        myCommand.CommandText = strAddSQL
        myCommand.Connection = cnConsOrders


    End Sub

Thanks for your help.
Question by:john0879
    LVL 9

    Expert Comment

    You forgot the FROM clause in your SQL statement.
    LVL 9

    Accepted Solution

    Nevermind, I mean this:

            Dim strSQL As String = "Select SCACLinehaul, MilesDCToPool, PostalCode from vw_Pool_Locations " & _
                                               "Where SailingDC = OriginLocation"

    A space after "vw_Pool_Locations" and "WHERE".

    Author Comment

    Thanks hismightiness.
    LVL 9

    Expert Comment

    No problem...  That happens way TOO often when we concatenate strings into SQL statements.  It is easily overlooked.  :)

    Author Comment

    The stupid error message never tell you where and what the exact error is:(

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video discusses moving either the default database or any database to a new volume.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now