这是什么原因 datagird的删除问题
日期:2007-04-16 荐:
这是什么原因 datagird的删除问题<asp:DataGrid id="MyList" runat="server" AutoGenerateColumns="False" Width="476px" OnItemCommand="MyDataGrid_Delete"><asp:ButtonColumn ItemStyle-Width="100px" Text="删除" CommandName="Delete" /></asp:DataGrid>public void MyDataGrid_Delete(Object sender, DataGridCommandEventArgs e){if(e.CommandName=="Delete") {string deleteCmd = "DELETE from pmailbox where id = @Id";SqlCommand myCommand = new SqlCommand(deleteCmd, MyConnection);myCommand.Parameters.Add(new SqlParameter("@Id", SqlDbType.VarChar,10));myCommand.Parameters["@Id"].Value = MyList.DataKeys[(int)e.Item.ItemIndex];myCommand.Connection.Open();myCommand.ExecuteNonQuery();myCommand.Connection.Close();}}id字段为 int 4“/job”应用程序中的服务器错误。--------------------------------------------------------------------------------索引超出范围。必须为非负值并小于集合大?gt;>2问
标签: