我该如何解决这个错误:
指数超出范围。必须是非负数且小于集合的大小。参数名称:索引
在这段代码中:
dataGridView1.AllowUserToAddRows = false;
dataGridView1.Columns.Add("ID", "ID");
dataGridView1.Columns.Add("Firstname", "Firstname");
dataGridView1.Columns.Add("MI", "MI");
dataGridView1.Columns.Add("Lastname", "Lastname");
dataGridView1.Columns.Add("Username", "Username");
dataGridView1.Columns.Add("Rights", "Rights");
c.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = c;
cmd.CommandText = "SELECT * From Account";
OleDbDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["ID"].Value = reader[0].ToString();
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Firstname"].Value = reader[1].ToString();
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["MI"].Value = reader[2].ToString();
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Lastname"].Value = reader[3].ToString();
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Username"].Value = reader[7].ToString();
dataGridView1.Rows[dataGridView1.Rows.Count - 1].Cells["Rights"].Value = reader[9].ToString();
}
c.Close();