A SELECT statement is a query. You don't use ExecuteNonQuery when you are,
in fact, querying the database. Since your query *can* return results, you
need to use the ExecuteReader method of your command, which returns a
DataReader object that you then use to look at the query results.
Try this:
Try
Dim con As New OleDbConnection("Provider=MicroSoft.Jet.OLEDB.4.0; Data
Source = " & Server.MapPath("Someplace.mdb"))
Dim cmd As New OleDbCommand("SELECT * from Cus where EMailAddress =" &
QM & Trim(txtEMail.Text) & QM, cnString)
con.Open()
Dim dr As Oledb.OledbDataReader = cmd.ExecuteReader()
If dr.HasRows Then
txtFirstName.Text = "Yes"
Else
txtFirstName.Text = "No " & Now
End If
Catch ex As Oledb.OledbException
'Database exceptions handled here
Catch ex As Exception
'All other exceptions handled here
Finally
dr.Close()
con.Close()
con.Dispose()
End Try
"Tony M" <To*************@msn.comwrote in message
news:e$**************@TK2MSFTNGP04.phx.gbl...
>
Shouldn't the ExecuteNonQuery be TRUE if it finds a record and FALSE is
not?
I get FALSE all the time and I seeded the database with the email address.
I just want to check if record exist before moving on.
If this doesn't work I guess I could load a datatable and check to see if
rows 0.
Dim cnString As OleDbConnection
cnString = New OleDbConnection("Provider=MicroSoft.Jet.OLEDB.4.0; Data
source = " & Server.MapPath("Someplace.mdb"))
Dim CheckCus As New OleDbCommand("SELECT * from Cus where EMailAddress ="
& QM & Trim(txtEMail.Text) & QM, cnString)
CheckCus.Connection.Open()
If CheckCus.ExecuteNonQuery() Then
txtFirstName.Text = "Yes"
Else
txtFirstName.Text = "No " & Now
End If
CheckCus.Connection.Close()
Thanks
Tony