0
votes
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)

1
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.Ricardo Souza
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.Ricardo Souza

1 Answers

0
votes

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