Check user input data exist in database: ERROR
Dim retVal As Boolean = False
Dim cnSQL As SqlConnection
Dim cmSQL As SqlCommand
Dim strSQL As String
strSQL = "Select * From Table_Contacts where EmailAddress = '" &
txtEmail.Text & "' OR Name = '" & txtName.Text & "';"
cnSQL = New SqlConnection(thisConnection)
cnSQL.Open()
cmSQL = New SqlCommand(strSQL, cnSQL)
Dim reader As SqlDataReader = cmSQL.ExecuteReader()
If Not reader.HasRows Then
retVal = False
MessageBox.Show("No Record")
Else
MessageBox.Show(" already exists!", " ", MessageBoxButtons.OK,
MessageBoxIcon.Error)
retVal = True
End If
cnSQL.Close()
cmSQL.Dispose()
cnSQL.Dispose()
retVal = True
Can someone help me with this?
I'm keep getting "already exist" even there is no matching record in the
database.
- Thanks
Date:Tue, 17 Jul 2007 17:01:23 -0400
Author:
|