[英]INSERT column Values from dataGridView INTO database table
保存 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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.