i have a webforms app using asp/C# .net with SQL server 2008. i have a login form that will authenticate access to my webform website. here is the code.
SqlConnection an = new SqlConnection(@"Data Source=REZRTECH\SQLEXPRESS;Initial Catalog=Temp;Integrated Security=True");
an.Open();
SqlCommand anc = new SqlCommand();
anc.Connection = an;
anc.CommandText = "Select * From Logins where User_name = @usr";
anc.Parameters.AddWithValue("@usr", TextBox1.Text);
int count = Convert.ToInt32(anc.ExecuteScalar());//throws input string was not in correct format exception.
if (count == 0)
{
string swa = "User Does Not Exist";
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + swa + "');", true);
return;
}
else
{
//
//if user name and password match goto homepage
{
Response.Redirect("~/Default.aspx");
}
else
{
string swa1 = "Invalid Login Credentials";
ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + swa1 + "');", true);
}
my table rows are both nvarchar. there is one other thing that is puzzling me, one user_name is admin and its corresponding password is also admin. suppose i enter any thing other than admin, it successfully gives me the error that user is not present. that time the "input string exception is not thrown"
any and all help is appreciated.