samedi 18 mars 2017

System.NullReferenceException: Object reference not set to an instance of an object.

 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "Delete")
    {
        try
        {
            int keyvalue = Convert.ToInt32(e.CommandArgument);
            //TextBox1.Text = keyvalue.ToString();
            con = new SqlConnection(str);
            con.Open();
            SqlCommand com = new SqlCommand("spDelete", con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddWithValue("@PatientId", keyvalue);

            cmd.ExecuteNonQuery();

            //da = new SqlDataAdapter(cmd);

            //GridView1.DataBind();
            con.Close();
        }
        catch (Exception ex)
        {
            Response.Write(ex);
        }


    }
}
trying to delete selected row but this error

System.NullReferenceException: Object reference not set to an instance of an object. at HospitalManagement.Edit.GridView1_RowCommand(Object sender, GridViewCommandEventArgs e) in C:\Users\sac\documents\visual studio 2015\Projects\HospitalManagement\HospitalManagement\Edit.aspx.cs:line 93

at cmd.commandType......... so help me

Aucun commentaire:

Enregistrer un commentaire