救命代码....大看一下这段代码,
for (int i = 0; i < GVMsg.Rows.Count; i++)
{
if (((CheckBox)GVMsg.Rows[i].FindControl("SelectChk")).Checked == true)
{
SqlConnection con = new SqlConnection(mstrCnn);
con.Open();
SqlCommand cmd = new SqlCommand("Delete T_Mssage where ID='" + GVMsg .DataKeys[i].Value + "'", con);
cmd.ExecuteNonQuery();
DisMsg();
con.Close();
}
}
总是说超出index索引值.
for (int i = 0; i < GVMsg.Rows.Count; i++)
{
if (((CheckBox)GVMsg.Rows[i].FindControl("SelectChk")).Checked == true)
{
SqlConnection con = new SqlConnection(mstrCnn);
con.Open();
SqlCommand cmd = new SqlCommand("Delete T_Mssage where ID=@Del", con);
SqlParameter paramDel = new SqlParameter("@Del", SqlDbType.Int, 4);
paramDel.Value = Convert.ToInt32(GVMsg.DataKeys[i].Value.ToString());
cmd.Parameters.Add(paramDel);
cmd.ExecuteNonQuery();
DisMsg();
con.Close();
}
}
换成这段代码也是一样哦.