Subin Thomas

Subin Thomas

  • NA
  • 4.9k
  • 117.3k

error in login code

Feb 18 2019 4:44 AM
i have written a login code which was sucessfuly working noe i have changes i need to take the uid and password from different table of same databse i changed the query where the table name i have changed and the field name but it is not working why
 
  1. string strSelect = "SELECT COUNT(*) FROM  [database name].[dbo].[tablename]  WHERE ReserveUID = @Username AND LoginPassword = @Password";  
  2.   
  3.             SqlConnection con = new SqlConnection(con_Vas);  
  4.             SqlCommand cmd = new SqlCommand();  
  5.             cmd.Connection = con;  
  6.             cmd.CommandType = CommandType.Text;  
  7.             cmd.CommandText = strSelect;  
  8.   
  9.             SqlParameter username = new SqlParameter("@Username", SqlDbType.NVarChar, 50);  
  10.             username.Value = txtusername.Text.Trim().ToString();  
  11.             cmd.Parameters.Add(username);  
  12.   
  13.             SqlParameter password = new SqlParameter("@Password", SqlDbType.NVarChar, 100);  
  14.             password.Value = Encrypt(txtpassword.Text.Trim());  
  15.             cmd.Parameters.Add(password);  
  16.   
  17.   
  18.             con.Open();  
  19.             int result = (Int32)cmd.ExecuteScalar();  
  20.             con.Close();  
  21.   
  22.             if (result >= 1)  
  23.             {  
  24.   
  25.                 Response.Redirect("ProjectDashboard.aspx");  
  26.             }  
  27.             else  
  28.             {  
  29.                 txtusername.Text = "";  
  30.                 txtpassword.Text = "";  
  31.                 Label1.Text = "invalid credential";  
  32.             }     
 

Answers (16)