Results 1 to 6 of 6

Thread: Does the SELECT statement return a value?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    108

    Smile 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?

  2. #2
    Hyperactive Member
    Join Date
    May 2006
    Posts
    365

    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

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  4. #4
    Hyperactive Member nagasrikanth's Avatar
    Join Date
    Nov 2004
    Location
    India,Hyderabad.
    Posts
    420

    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.. :-)
    The Difference between a Successful person and others is not a Lack of Knowledge,
    But rather a Lack of WILL

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Mar 2006
    Posts
    108

    Re: Does the SELECT statement return a value?

    yup thanks for the replies guys

  6. #6
    Addicted Member
    Join Date
    Mar 2006
    Location
    Manchester, England, UK
    Posts
    247

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width