Error: System.NullReferenceException: Object reference not set to an instance of an object
Please help me fix it.
protected void Inkview_Click(object sender, EventArgs e)
{
gvDetails.UseAccessibleHeader = true;
gvDetails.HeaderRow.TableSection = TableRowSection.TableHeader;
int rowIndex = ((sender as Button).NamingContainer as GridViewRow).RowIndex;
int lbl1 = Convert.ToInt32(gvDetails.DataKeys[rowIndex].Values[0]);
SqlConnection con = new SqlConnection("data source=NERE\\SQLEXPRESS01; Initial Catalog=kaging;Integrated Security=True;");
SqlCommand cm = new SqlCommand();
cm.Connection = con;
con.Open();
cm.CommandType = CommandType.Text;
cm.CommandText = "SELECT productcodeM FROM orders WHERE id= ' " + lbl1 + "' ";
Session["r"] = Convert.ToString(cm.ExecuteScalar());
updateSQL = "update stock set active='0' where ppid='" + Session["r"].ToString() + "'";
dbConn.ConnectionString = "data source=NERE\\SQLEXPRESS01; Initial Catalog=kaging;Integrated Security=True;";
cmd.Connection = dbConn;
cmd.CommandText = updateSQL;
cmd.CommandType = CommandType.Text;
try
{
dbConn.Open();
int updated = cmd.ExecuteNonQuery();
if (updated == 1)
{
// Response.Redirect("Cylin.aspx");
}
else
{
// Label1.Text = "Process not Completed";
}
}
catch (Exception err)
{
Response.Write(err.ToString());
}
finally
{
dbConn.Close();
}
BindUserDetails();
con.Close();
Response.Redirect("UseableCyl.aspx");
}