Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Column name invalid 1

Status
Not open for further replies.

tsp1lrk72

IS-IT--Management
Feb 25, 2008
100
US
Hello,

I have some code:

Code:
  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
        End If
        'Define connection to read the data 
        Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
        Dim MyCmd As New SqlCommand("SELECT EmployeeID, Password From tblVendorLogin Where EmployeeID =  " & Request.Cookies("SKUPM")("EmpID"), myConn)
        MyCmd.CommandType = CommandType.Text
        MyCmd.Parameters.Add(New SqlParameter("@EmployeeID", SqlDbType.VarChar, 7)).Value = Convert.ToString(EmployeeID)
        myConn.Open()
        Dim Result As SqlDataReader = MyCmd.ExecuteReader(CommandBehavior.CloseConnection)
        Result.Read()
        If Not Result.IsDBNull(0) Then
            EmployeeID.Text = Result("EmployeeID").ToString()
        End If
        If Not Result.IsDBNull(0) Then
            txtCurrent.Text = Result("Password").ToString()
        End If

    End Sub

I keep getting: Invalid column name 'lisa'.

lisa is one of the Employee ID's... the minute I delete that from my table and deal only with numbers, for instance, 1111111 as the Employee ID, my code is fine-- It's a SQL thing I think, (I posted there too) but I'm thinking it's the way I'm calling the Employee ID- is Char okay to use? Why is it as soon as I have alphanumeric characters I get that message???? What is wrong???

Thanks!
 
If employee ID is char (a string), you need to enclose it in single quotes:
EmployeeID = '" & Request.Cookies("SKUPM")("EmpID") & "'",

"Business conventions are important because they demonstrate how many people a company can operate without."
 
Thanks, that did the trick.... Most appreciated!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top