int n = Convert.ToInt32(GridProduct.SelectedRows[0].Cells[0].Value);
int ill = GrdSubProduct.Rows.Count;
if (GridProduct.Rows.Count > 1 && GridProduct.SelectedRows[0].Index != GridProduct.Rows.Count - 1)
{
SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand("SP_Del_DeleteBySubProductID", con);
cmd.Parameters.AddWithValue("@ID", GridProduct.SelectedRows[0].Cells[0].Value);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
int i = cmd.ExecuteNonQuery();
if (i > 0)
MessageBox.Show(" Product Delete");
GetProduct();
}
帮助我............
答案 0 :(得分:0)
哪一行导致异常?我的猜测是第一行,因为如果你没有将SelectionMode设置为FullRowSelect,那么GridProduct.SelectedRows为null,这不是默认值......
MSDN:
SelectionMode属性必须设置为FullRowSelect或RowHeaderSelect,以便使用选定的行填充SelectedRows属性。