Whats wrong with this my SELECt Query >?

Posted by user559800 on Stack Overflow See other posts from Stack Overflow or by user559800
Published on 2011-01-12T12:48:16Z Indexed on 2011/01/12 12:53 UTC
Read the original article Hit count: 190

Filed under:
|
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim SQLData As New System.Data.SqlClient.SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
        Dim cmdSelect As New System.Data.SqlClient.SqlCommand("SELECT COUNT(*) FROM Table1 WHERE Name =" + TextBox1.Text + " And Last = '" + TextBox2.Text + "'", SQLData)
        SQLData.Open()
        If cmdSelect.ExecuteScalar > 0 Then
            Label1.Text = "Record Found ! " & TextBox1.Text & " " & TextBox2.Text
            Return
        End If

        Label1.Text = "Record Not Found ! "
        SQLData.Close()
    End Sub

I write this code to find whether the record entered in textbox1 and textbox2 exists or not ..if record exist ..then in label1 the text would be RECORD FOUND else NO RECORD FOUND

ERROR :

**when i enter in textbox1 and textbox2 then on button click event it shows the error : Invalid column name ,,**

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about vb.net