hello i am trying to run a command to test if some records are already in a database table. but on test i get this syntax error
incorrect syntax near ')'
and here is the code:
can someone plze help me...
full function:
incorrect syntax near ')'
and here is the code:
Code:
"IF EXISTS (SELECT * FROM table_login WHERE username='" + TextBox1.Text.ToString + "' AND password='" + TextBox2.Text.ToString + "')"
full function:
Code:
Private Function CustomerCheck()
Dim connString As String = ("Server = .\SQLEXPRESS; AttachDbFilename = C:\db_login.mdf; Trusted_Connection=Yes;User Instance = True;")
Dim cmdText As String = "IF EXISTS (SELECT * FROM table_login WHERE username=" + TextBox1.Text.ToString + " AND password=" + TextBox2.Text.ToString + ")"
Dim bRet As Boolean = False
Dim Test As Integer
Try 'opens the connection with the given connString
Using sqlConnection As SqlClient.SqlConnection = New SqlClient.SqlConnection(connString)
sqlConnection.Open()
'gives query to the connection
Using sqlCmd As SqlCommand = New SqlCommand(cmdText, sqlConnection)
'checks if rows exist and returns TRUE or FALSE
Test = CInt(sqlCmd.ExecuteScalar)
End Using
End Using
If Test = 0 Then 'no results
Else
'some(results)
End If
Catch ex As SqlException
MessageBox.Show(ex.Message)
End Try
Return (bRet)
End Function