lidds Posted April 21, 2005 Posted April 21, 2005 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 "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 Quote
Mister E Posted April 21, 2005 Posted April 21, 2005 Depending on your DBMS, you could do:select * from regdetails where LOWER(username)=LOWER(@username) AND password=@password And then, assuming you have a DataSet "ds":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. Quote
HJB417 Posted April 21, 2005 Posted April 21, 2005 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.