Kavi suja

Kavi suja

  • NA
  • 298
  • 171.2k

ASP.NET C# MySql

Apr 27 2013 6:15 AM
Hi,
  i'm new to this field.Now i'm trying to create login form with MySql as DB.I've following error.
Can anyone help me?



On SubmitButton_Click onclick event:
string constr = "server=localhost;user name=root;password=pwd;database=contacts";
            MySqlConnection con = new MySqlConnection(constr);            
            query = "SELECT Count(*) FROM contacts WHERE username='" + nametxt.Text + "' AND password='" + pwdtxt.Text + "'";
            MySqlCommand com = new MySqlCommand(query, con);
            con.Open();
            string result = string.Empty;
            int aa = Convert.ToInt32(com.ExecuteScalar().ToString());
            con.Close();            
            if(aa==0)
            {
                lblerr.Text = "Invalid username or password";                
            }
            else
            {
                Response.Redirect("detailadd.aspx");                
            }

error:
unhandled exception by user

Thanks in advance

Answers (4)