为什么这样可以,注释的那部分方法不行?出错。谢谢回答。
int j = dataGridView1.SelectedRows.Count;
int[] l = new int[j]; int i;
for (i = 0; i < j; i++)
{
l[i] = dataGridView1.SelectedRows[i].Index;
} int k = 0;
while (k < j)
{
this.northwindDataSet.Customers.Rows[l[k]].Delete();
k++;
}
//this.customersTableAdapter.Update(this.northwindDataSet.Customers); //int count = dataGridView1.SelectedRows.Count;
//for (int i = 0; i < count; i++)
//{
// this.northwindDataSet.Customers.Rows.RemoveAt(dataGridView1.SelectedRows[i].Index);
//}
//foreach (DataGridViewRow dr in dataGridView1.Rows)
//{
// if (dr.Selected)
// {
// this.northwindDataSet.Customers.Rows[dr.Index].Delete();
// }
//}
try
{
this.customersTableAdapter.Update(this.northwindDataSet.Customers);
}
catch (Exception e1)
{
MessageBox.Show(e1.Message);
}
int j = dataGridView1.SelectedRows.Count;
int[] l = new int[j]; int i;
for (i = 0; i < j; i++)
{
l[i] = dataGridView1.SelectedRows[i].Index;
} int k = 0;
while (k < j)
{
this.northwindDataSet.Customers.Rows[l[k]].Delete();
k++;
}
//this.customersTableAdapter.Update(this.northwindDataSet.Customers); //int count = dataGridView1.SelectedRows.Count;
//for (int i = 0; i < count; i++)
//{
// this.northwindDataSet.Customers.Rows.RemoveAt(dataGridView1.SelectedRows[i].Index);
//}
//foreach (DataGridViewRow dr in dataGridView1.Rows)
//{
// if (dr.Selected)
// {
// this.northwindDataSet.Customers.Rows[dr.Index].Delete();
// }
//}
try
{
this.customersTableAdapter.Update(this.northwindDataSet.Customers);
}
catch (Exception e1)
{
MessageBox.Show(e1.Message);
}
如果用foreach 不允许修改其成员