,但是它说:“索引超出范围。必须为非负数,并且小于集合参数名称:index的大小” 这是什么意思?我的代码有问题吗?
private void button2_Click(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("No Invoice", typeof(String));
dt.Columns.Add("Tanggal", typeof(string));
dt.Columns.Add("Nama Barang", typeof(string));
dt.Columns.Add("Ukuran", typeof(string));
dt.Columns.Add("Harga Satuan", typeof(String));
dt.Columns.Add("Quantity", typeof(String));
dt.Columns.Add("Sub Total", typeof(int));
dt.Columns.Add("Total", typeof(String));
dt.Columns.Add("namaCus", typeof(String));
foreach (DataGridViewRow dgv in dataGridView1.Rows)
{
dt.Rows.Add(dgv.Cells[0].Value, dgv.Cells[1].Value, dgv.Cells[2].Value, dgv.Cells[3].Value, dgv.Cells[4].Value, dgv.Cells[5].Value, dgv.Cells[6].Value, dgv.Cells[7].Value, dgv.Cells[8].Value);
}
if (dt.Rows.Count != 0)
{
dt.Rows.RemoveAt(dt.Rows.Count - 1);
}
CryRpt rpt = new CryRpt();
rpt.Database.Tables["tabel_invoice"].SetDataSource(dt);
Print_Invoice print_form = new Print_Invoice(rpt);
print_form.Show();
}