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)