0
protected void Button1_Click(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection("Data Source=PIYUSH-PC\\SQLEXPRESS;Initial Catalog=piyush;Integrated Security=True");
    SqlCommand cmd = new SqlCommand("SPRegisterUser", con);

    cmd.CommandType = CommandType.StoredProcedure;

    SqlParameter username = new SqlParameter("@Username_V", TextBox1.Text);
    SqlParameter email = new SqlParameter("@Email_V", TextBox2.Text);
    SqlParameter password = new SqlParameter("Password_V", TextBox3.Text);

    cmd.Parameters.Add(username);
    cmd.Parameters.Add(password);
    cmd.Parameters.Add(email);
    try
    {
        con.Open();
        int ReturnCode = (int)cmd.ExecuteScalar();
        if (ReturnCode == -1)
        {
            Response.Write("Username already exists");
        }
        else
        {
            Response.Redirect("WebForm2.aspx");
        }
    }
    catch (Exception e1)
    {
        Response.Write(e1);
    }
    finally
    {
        con.Close();
    }
}

The above code runs but shows the following- System.NullReferenceException: Object reference not set to an instance of an object. at eGaffar_23_6_2014_.WebForm1.Button1_Click(Object sender, EventArgs e)

2
  • This is definitely not classic ASP, it's ASP.Net. Classic ASP was written in VBScript or JavaScript and would not have events like button clicks, etc. Commented Jul 1, 2014 at 16:15
  • Probably your textboxes are named different from the above. Try running this on debug mode, hitting F5 or click the Play icon on the toolbar of Visual Studio or Visual Web Developer. Commented Jul 1, 2014 at 16:17

1 Answer 1

0

Your 3rd Parameter has to be @Password_V because while Passing a parameter of value you need to add @ also

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.