Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   Working with OrcaleDataAdapter (http://www.go4expert.com/forums/working-with-orcaledataadapter-t15442/)

PoOoZaQ 8Dec2008 20:24

Working with OrcaleDataAdapter
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 8Dec2008 20:43

Re: Working with OrcaleDataAdapter
Bind variables are for data only. You cannot do "set :var =" or "where :var ="; these must be literal values.

PoOoZaQ 9Dec2008 01:08

Re: Working with OrcaleDataAdapter
I see.

Well I solved the problem with OracleCommandBuilder anyway :)

Thanks, can be closed

All times are GMT +5.5. The time now is 16:16.