Invalid Column Name RRS feed

  • Question

  • I'm getting Invalid column name 'CHARLES'. Invalid column name 'CHARLYN'. Invalid column name 'SMITH'. Could somebody point out what's wrong with my code, it's been a long time since I used SQL dataset.  I'm into LINQ but I'm having problems with this kind of LINQ query so I'm reverting to SQL dataset.


    here's my code:

            'Set up a data set command object.
            Dim sSelectColumn As String = ("SELECT * FROM tblScanned WHERE LastName=" & sLastName & " AND FirstName =" & sFirstName & " AND MiddleName =" & sMiddleName)
            Dim sqlMyDataAdapter As New SqlDataAdapter(sSelectColumn, sqlMyConnection)

            'Load the dataset
            Dim dsMyDataset As DataSet = New DataSet
            sqlMyDataAdapter.Fill(dsMyDataset, "tblScanned")

    Wednesday, June 2, 2010 8:47 AM


  • First of all your code is not Linq but AdoNet.

    Secondly, in SQL transact non numbers have to be between single quotes.

    By the way, your code is not as it could be (you can better use parameters)

    However, that is not the the reason of the not acceptaning your string.

    Try those single quotes first and if it works, create then a new question how to do it with parameters.


    • Marked as answer by Alex Liang Wednesday, June 9, 2010 3:14 AM
    Wednesday, June 2, 2010 9:53 AM