GridView

Jul 13 2015 4:19 AM
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox UserName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1");
string EmailAddress = GridView1.DataKeys[e.RowIndex].Values["EmailAddress"].ToString();
TextBox FirstName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox3");
TextBox LastName = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox4");
TextBox Password = (TextBox)GridView1.Rows[e.RowIndex].FindControl("Password");
TextBox ConformPassword = (TextBox)GridView1.Rows[e.RowIndex].FindControl("ConformPassword");
TextBox Address = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox7");
DropDownList State = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DDL1");
DropDownList City = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("DDL2");
Con.Open();
String S = "Update Registration set UserName='" + UserName.Text + "',FirstName='" + FirstName.Text + "',LastName='" + LastName.Text + "',Password='" + Password.Text + "',ConformPassword='" + ConformPassword.Text + "',Address='" + Address.Text + "',State='" + State.SelectedItem + "',City='" + City.SelectedItem + "' where EmailAddress='" + EmailAddress + "'";
//string S = "Update Registration set UserName=@p1,FirstName=@p3,LastName=@p4,Password=@p5,ConformPassword=@p6,Address=@p7,State=@p8,City=@p9 where EmailAddress=@p2";
SqlCommand Cmd = new SqlCommand(S, Con);
//Cmd.Parameters.AddWithValue("@p1", UserName);
//Cmd.Parameters.AddWithValue("@p2", EmailAddress);
//Cmd.Parameters.AddWithValue("@p3", FirstName);
//Cmd.Parameters.AddWithValue("@p4", LastName);
//Cmd.Parameters.AddWithValue("@p5", Password);
//Cmd.Parameters.AddWithValue("@p6", ConformPassword);
//Cmd.Parameters.AddWithValue("@p7", Address);
//Cmd.Parameters.AddWithValue("@p8", State);
//Cmd.Parameters.AddWithValue("@p9", City);
Cmd.ExecuteNonQuery();
Con.Close();
GridView1.EditIndex = -1;
GetData();
}
 
 I am getting this error Hoe to solve please tell me argent
 

Object reference not set to an instance of an object. in this line

 
String S = "Update Registration set UserName='" + UserName.Text + "',FirstName='" + FirstName.Text + "',LastName='" + LastName.Text + "',Password='" + Password.Text + "',ConformPassword='" + ConformPassword.Text + "',Address='" + Address.Text + "',State='" + State.SelectedItem + "',City='" + City.SelectedItem + "' where EmailAddress='" + EmailAddress + "'";
 
 
 

Answers (3)