By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,269 Members | 1,509 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,269 IT Pros & Developers. It's quick & easy.

how to get exactl y information from the database

P: 29

i have an aspx page that Contains tow textBoxs and Button

i Must enter a correct username at the textbox 1 and password in textbox 2 that exists in database

my command have this code

Expand|Select|Wrap|Line Numbers
  1. MyCom = new SqlCommand("select * from Users where UserName='"+TextBox1.Text+"' and Password='"+TextBox2.Text+"'",MyCon);
i want to show an error message that containt "Your Password is Wrong" if the user enter a correct user name but wrong Password

and another message that say "UserName Is not found in our db" if the user enter an unavalable username

i used this code

Expand|Select|Wrap|Line Numbers
  1. if (DataReader.Read())
  2.         {
  3.             Response.Redirect("Default.aspx?uname="+TextBox1.Text);
  4.         }
  5.         else
  6.         {
  7.             MessageBox.Show("Invaild Data");
  8.         }
but its not say where is the error exactly

its dont say if the username is wrong or the password

its just say invaild data

any body can help me ?!?
Mar 2 '07 #1
Share this Question
Share on Google+
1 Reply

P: 1
The only way is if you evaluate first if user exists,
"select count(*) from Users where UserName=@UserName"
execute and continues if result is 1, returns CustomCodeError like -1

then validate the user and password

"select count(*) from Users where UserName=@UserName and Password=@Password"

execute and returns 1 if is succesfull, and return -2 if not,

in the call to your function evaluate the result and show to the user the specific message for the result.

Elmer Carķas
TI Consultant
El Salvador, Central America.
Mar 2 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.