Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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.

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...