Working with OrcaleDataAdapter

PoOoZaQ's Avatar, Join Date: Jul 2008
Newbie Member
Hey everyone.

I am kinda a young programmer so bear with me

I am having difficulties updating rows in the DB when working with a dynamic data adapter update command.

This means that not only I specify the changed value, I also specify the columns where the change is done.

Short description:
I am implementing a RollBack function, I have a table containing changes done in different tables.
That table includes the fields:
TABLE_NAME - name of the table where the change was done
NEW_VALUE - The value the field changed to.
OLD_VALUE - The previous value the field had
FIELD_NAME - The field name where the change was done

some other irrelevant fields that contain the PK's field name and value.


So basically when I try to update it would look like that:
foreach (DataRow drChangedRow in dtChangedTbl.Rows)
{
drTableToUpdate[drChangedRow[FIELD_NAME]] = drChangedRow[OLD_VALUE];
}

(Sorry for the detailed desc just don't want misunderstandings)

Now when I try to update the OracleDataAdapter, I need to specify an UpdateCommand to it.

What I thought of is:
OracleCommand cmdUpdate =
new OracleCommand("UPDATE strTableName" +
"SET :FieldName = :FieldValue" +
"WHERE :PKFieldName = :PKFieldValue");

cmdUpdate.Parameters.Add("FieldName", OracleDbType.VarChar2);
cmdUpdate.Parameters.Add("FieldValue", OracleDbType.VarChar2);
cmdUpdate.Parameters.Add("PKFieldName ", OracleDbType.VarChar2);
cmdUpdate.Parameters.Add("PKFieldValue", OracleDbType.VarChar2);

It doesn't work...

My only guess is needing to connect somehow the parameter name with actually how I insert the info.


Any help would be appreciated.
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Bind variables are for data only. You cannot do "set :var =" or "where :var ="; these must be literal values.
PoOoZaQ's Avatar, Join Date: Jul 2008
Newbie Member
I see.

Well I solved the problem with OracleCommandBuilder anyway

Thanks, can be closed