如何使用OleDbDataAdapter和sql查询更新数据库?

时间:2012-10-19 12:40:47

标签: c# ado.net

我有这段代码:

OleDbDataAdapter dataAdapter = new OleDbDataAdapter("SELECT col1, col2 "
                                                  + "FROM tab1", 
                                                    connection);

我希望能够这样做:

dataAdapter.UpdateCommand = new OleDbCommand(
            "UPDATE tab1 SET col1 = col1*2, col2 = 300"
          + "WHERE col1 = 5", connection);

如何做到这一点?

1 个答案:

答案 0 :(得分:2)

就这样使用它:

var cmd = new OleDbCommand("UPDATE tab1 SET col1 = col1*2, col2 = 300 WHERE col1 = 5", connection);
cmd.ExecuteNonQuery();

您不需要数据适配器。