我正在编程一个应在单击按钮后将DataGridView插入Oracle的应用程序。我怎么知道最后插入到Oracle中的行数。充其量应该出现一条消息。谢谢
private void button4_Click(object sender, EventArgs e)
{
try
{
for (int i = 0; i < dataGridViewDoubleBuffered1.Rows.Count - 1; i++) //Schleife für INSERT Befehl
{
OracleConnection con = new OracleConnection(XXXXXXX);
con.Open();
string sql = "INSERT INTO AFTERSALES.INPUT_BOARDLEVEL_REPAIR_LDS (BLR_REPORT_DATE, MONTH_OF_REPAIR_END, PCB_COUNTER) "
+ "VALUES (:BLR_REPORT_DATE, :MONTH_OF_REPAIR_END, :PCB_COUNTER)";
OracleCommand cmd = new OracleCommand(sql, con);
cmd.CommandText = sql;
cmd.Parameters.Add(":BLR_REPORT_DATE", Convert.ToString(dataGridViewDoubleBuffered1.Rows[i].Cells[0].Value));
cmd.Parameters.Add(":MONTH_OF_REPAIR_END", dataGridViewDoubleBuffered1.Rows[i].Cells[1].Value);
cmd.Parameters.Add(":PCB_COUNTER", dataGridViewDoubleBuffered1.Rows[i].Cells[2].Value);
cmd.ExecuteNonQuery();
con.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
答案 0 :(得分:0)
ExecuteNonQuery返回受影响的行数。
所以
var numRowsInserted = cmd.ExecuteNonQuery();
答案 1 :(得分:0)
int recordsAffected = cmd.ExecuteNonQuery();
返回Int32对于UPDATE,INSERT和DELETE语句,返回 值是受命令影响的行数。