【发布时间】:2021-05-04 00:02:48
【问题描述】:
【问题讨论】:
-
请显示您的代码并准确描述什么不起作用。
-
@Crowcoder 我真的不知道将这些列值插入到数据库表中的代码是什么,我试图将它们存储到一个数组中,然后我使用了 INSERT 查询,但它没有按预期工作..
标签: c# database datagridview
【问题讨论】:
标签: c# database datagridview
保存 datagridview 的前 3 个单元格,上述查询仅适用于 3 及其倍数,但这样我可以
OleDbCommand command = new OleDbCommand (@"insert into tb
(hb,urea,ca)
Values
(@hb,@urea,ca)", database.con);
int RowInsert = dataGridView1.RowCount / 3;
int i = 0;
int control =1;
while (true)
{
command.Parameters.AddWithValue("@hb", $"{dataGridView1.Rows[i].Cells[2].Value}");
command.Parameters.AddWithValue("@urea", $"{dataGridView1.Rows[i+1].Cells[2].Value}");
command.Parameters.AddWithValue("@ca", $"{dataGridView1.Rows[i+2].Cells[2].Value}");
command.ExecuteNonQuery();
if (RowInsert==control)
{
break;
}
i += 3;
control++;
}
MessageBox.Show("Success", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
【讨论】:
"@ca", $"{dgr.Cells[2].Value}"