Does the SELECT statement return a value?
Hi,
I am setting up a user login account database. It consists of a table containg ID, username and password attributes.
First,the database will be searched to see if such a user exists.
What happens if the SELECT statement doesnt find a match? Does it return a value to indicate that there is no record found?
Re: Does the SELECT statement return a value?
Hello Lilo,
No the select statement will not inform the user of no records found but within the select statement you could use a COUNT(ID) AS mycount following the Select tablename.ID then test the value of mycount > 0.
Steve
Re: Does the SELECT statement return a value?
A SELECT will open and create a recordset. Whether there is anything in the recordset will determine if the username is found. If you compare what is returned to what has been typed into the login textbox, you will know whether there is match.
Re: Does the SELECT statement return a value?
You can check out the number of records returned by the select statement..
if RecordCount property returns 0 then that means the user doesn't exist.. :-)
Re: Does the SELECT statement return a value?
:thumb: yup thanks for the replies guys
Re: Does the SELECT statement return a value?
If you don't want to actually do anything with the user record other than check it exists I wouldn't even use a recordset. Your adding unecessary weight to your application.
A typical command would be :
Code:
SELECT Count(UserID)
FROM tbl_Users
WHERE UserName LIKE @UserName
AND Password = @Password
Execute this using a connection and a command to populate the parameters and get the return value and you'll have a more robust application.
You should always use parameterised SQL where ever possible.