public partial class SignUp : System.Web.UI.Page { SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbcon"].ToString());
public int chkuser()
{
if (con.State.ToString() == "open")
con.Close();
SqlCommand cmd = new SqlCommand("select count(*) from Task2_SignUp where UserName= '"+txtUName.Text+"'",con);
con.Open();
int flag = Convert.ToInt32(cmd.ExecuteScalar().ToString());
return flag;
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSignUp_Click(object sender, EventArgs e)
{
if(chkuser()==0)
{
if (con.State.ToString() == "open")
con.Close();
SqlCommand cmd = new SqlCommand("insert into Task2_SignUp (UserName,Password,Name) values (@UserName, @Password, @Name)", con);
cmd.Parameters.AddWithValue("@Username", txtUName.Text);
cmd.Parameters.AddWithValue("@Password", txtPassword.Text);
cmd.Parameters.AddWithValue("@Name", txtName.Text);
con.Open(); //ERROR SHOWING IN THIS LINE
cmd.ExecuteNonQuery();
con.Close();
lblSignUp.Text = "Registration Successfull";
_blank();
}
else if(chkuser()>0)
{
lblSignUp.Text = "Username not available";
}
}
public void _blank()
{
txtName.Text = "";
txtUName.Text = "";
txtPassword.Text = "";
}
protected void btnNext_Click(object sender, EventArgs e)
{
Response.Redirect("Login.aspx");
}
}
}
QUESTION : This is the error i am getting dont know why.. and suprprisingly this same code worked two weeks back but not working now.. please help me if possible.