1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Working with OrcaleDataAdapter

Discussion in 'C#' started by PoOoZaQ, Dec 8, 2008.

  1. PoOoZaQ

    PoOoZaQ New Member

    Joined:
    Jul 12, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,012
    Likes Received:
    203
    Trophy Points:
    0
    Occupation:
    Senior Support Engineer
    Location:
    England
    Bind variables are for data only. You cannot do "set :var =" or "where :var ="; these must be literal values.
     
  3. PoOoZaQ

    PoOoZaQ New Member

    Joined:
    Jul 12, 2008
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    I see.

    Well I solved the problem with OracleCommandBuilder anyway :)

    Thanks, can be closed
     

Share This Page