获取indexoutorange异常
本文关键字:异常 indexoutorange 获取 | 更新日期: 2023-09-27 17:51:12
得到一个异常消息"There is no row at position 1"
如果我们在datatgridview中输入2行或更多,并单击save按钮,它只插入第一行,并给出一个异常。
下面是代码片段:private void btnSave_Click(object sender, EventArgs e)
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
table = obj.select("select id from stock where item_name='" + dataGridView1.Rows[i].Cells[0].FormattedValue + "'");
obj.query("insert into poi_items (po_id, stock_id, description, expected_price, discount, quantity, expected_total, status, received)values(" + textBox3.Text + "," + table.Rows[i][0] + ",'" + dataGridView1.Rows[i].Cells[1].FormattedValue + "'," + dataGridView1.Rows[i].Cells[3].FormattedValue + "," + dataGridView1.Rows[i].Cells[5].FormattedValue + "," + dataGridView1.Rows[i].Cells[2].FormattedValue + "," + dataGridView1.Rows[i].Cells[6].FormattedValue + ",'Open','0')");
}
}
似乎在你的查询
table.Rows[i]
是引发异常的原因。请确保表中有2行