下面是更新的代码:
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Server.MapPath("/TouchScreen/Meet.mdb");
conn = new OleDbConnection(strConn);
string strUpdate = "UPDATE meetguide set title=@title,content=@content";
OleDbCommand myCommand = new OleDbCommand(strUpdate,conn); myCommand.Parameters.Add(new OleDbParameter("@title",OleDbType.VarChar,30));
myCommand.Parameters.Add(new OleDbParameter("@content",OleDbType.VarChar,100)); myCommand.Parameters["@title"].Value = DataGrid1.DataKeys[e.Item.ItemIndex]; string[] Cols = new string[]{"@title","@content"};
int NumCols = e.Item.Cells.Count; for(int i=2;i<=NumCols - 1;i++)
{
TextBox CurrentTextBox = (TextBox)e.Item.Cells[i].Controls[0];
string ColValue = CurrentTextBox.Text; if(ColValue == "")
{
Label1.Text = "不能有空!";
return;
}
}
conn.Open();
try
{
myCommand.ExecuteNonQuery();
DataGrid1.EditItemIndex = -1;
}
catch (OleDbException d)
{
Label1.Text = d.ToString();
}
conn.Close();
Bind(); }
}Pageload的时候我已经加了if(!IsPostBack) 
但是点了更新按钮后出现如下错误信息:指定的参数已超出有效值的范围。参数名: index 
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.ArgumentOutOfRangeException: 指定的参数已超出有效值的范围。参数名: index源错误: 
行 163: for(int i=2;i<=NumCols - 1;i++)
行 164: {
行 165: TextBox CurrentTextBox = (TextBox)e.Item.Cells[i].Controls[0];
行 166: string ColValue = CurrentTextBox.Text;
行 167: