checking if user exists...

lidds

Junior Contributor
Joined
Nov 9, 2004
Messages
210
I am very new to asp and was wondering the best way to check if a user already exists. Obviously this would envolve a select query

Code:
"select * from regdetails where username='simon'"

and then to check to see if any items are within the recordset, but I am unsure how to write the code to do so, can anyone post an example of code???

Cheers

Simon
 
Depending on your DBMS, you could do:
Code:
select * from 
regdetails 
where LOWER(username)=LOWER(@username) AND password=@password

And then, assuming you have a DataSet "ds":
Code:
bool valid = (ds.Tables[0].Rows.Count > 0);

Note: make sure to test case sensitivity on the SQL query for your particular DBMS. The above would work for SQL Server.
 
Code:
GenericDbCommand cmd;
cmd.CommandText = "select count(*) from regdetails where username=@username";
cmd.Parameters.Add("@username", "simon");
bool exists = Convert.ToBoolean(cmd.ExecuteScalar());
please choose the appropriate sql for the right job.
treat the data returned by the sql server like the items you take on a hiking trip (you only take what you need)
In this case, you dont need all of the data of all of the columns for 1 records in the 'regdetails' table. Use count() instead.
 
Back
Top