【发布时间】:2014-09-21 11:17:07
【问题描述】:
我有一种方法可以将 datagridview 中的每一行保存到数据库中,但如果每一行被保存,我想删除它。我有这个方法:
public static void SaveMajEq(MajorEquipment_CreateView CView)
{
rowCount = 0;
// For each cell in the DataGrid, stores the information in a string.
for (rows = 0; rows < CView.dgvCreate.Rows.Count; rows++)
{
if (CView.dgvCreate.Rows[rows].Cells[col].Value != null)
{
// Creates a model, then populates each field from the cells in the table.
MeModel = new MajorEquipment_Model();
MeModel.EquipmentNumber = Convert.ToString(CView.dgvCreate.Rows[rows].Cells[0].Value);
MeModel.EquipmentType = Convert.ToString(CView.dgvCreate.Rows[rows].Cells[1].Value);
MeModel.Location = Convert.ToString(CView.dgvCreate.Rows[rows].Cells[2].Value);
MeModel.Notes = Convert.ToString(CView.dgvCreate.Rows[rows].Cells[3].Value);
Database_Facade.Operation_Switch(OPWRITE);
}
CView.dgvCreate.Rows.RemoveAt(rows);
}
MessageBox.Show(rowCount + " Entries stored in database.");
}
rowCount 在单独的类中的 try/catch 方法中递增,因此如果发生任何事情,它不会递增。我想做的只是实现这一行:
CView.dgvCreate.Rows.RemoveAt(rows);
仅当 rowCount 每次都增加时。我不知道如何实现这一点。
【问题讨论】:
标签: c# mysql datagridview