Romz
Romz

Reputation: 1457

How to update database using OleDbDataAdapter with sql query?

I have this code:

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

I want to be able to do like this:

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

How to do this right ?

Upvotes: 1

Views: 1449

Answers (1)

Mike Perrenoud
Mike Perrenoud

Reputation: 67898

Just use it like this:

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

You don't need a data adapter.

Upvotes: 2

Related Questions