What's wrong with this SQL Server query ?

Posted by ClixNCash on Stack Overflow See other posts from Stack Overflow or by ClixNCash
Published on 2011-01-15T07:39:15Z Indexed on 2011/01/15 9:53 UTC
Read the original article Hit count: 245

Filed under:
|
|

What's wrong this T-SQL query :

 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 + "'", SQLData)
        SQLData.Open()
        If cmdSelect.ExecuteScalar > 0 Then
            Label1.Text = "You have already voted this service"
            Return
        End If
        Dim con As New SqlConnection
        Dim cmd As New SqlCommand
        con.Open()
        cmd.Connection = con
        cmd.CommandText = "INSERT INTO Tabel1 (Name) VALUES('" & Trim(Label1.Text) & "')"
        cmd.ExecuteNonQuery()
        Label1.Text = "Thank You !"
        SQLData.Close()
    End Sub

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about sql-server