Search code examples
c#oracle-databasevisual-studiooledb

OLEDBConnection: Insert byte[] into blob doesn't save change


I am trying to update records using OLEDBconnection. The data I wanted to update, in array of bytes, will be stored as blob in the oracle. However, when the line hits the ExecuteNonQuery, nothing gets changed

What I have tried:

I thought there was problem with the query itself. So I have tried the following:

1: Test with other query:

@"UPDATE dcmnts 
             SET TestCol = ?
             where BUSNSS_ID = ?";

By running this, the TestCol was updates successfully. It is a varchar column

2: Made sure that the binding are in the same order appears in the query as the question marks, did not work either

3: Put a Console.WriteLine at the end, and it prompts: "1 row with 12345678 updated", so it does get updated, but when I check the Oracle Developer, Summary_SPOD column is still null

    public void SaveSPODLetter(byte[] Letter, string TrackingNumber )
    {
        string query = @"UPDATE dcmnts 
                         SET SUMMARY_SPOD = ?
                         where BUSNSS_ID = ?";
        OleDbCommand command = null;
        string ConnString = ConfigurationManager.ConnectionStrings["My_db"].ToString();

        using (OleDbConnection connection = new OleDbConnection(BaseEncryptor.DecryptString(ConnString)))
        {
            try
            {
                if (connection.State != ConnectionState.Open)
                    connection.Open();
                command = new OleDbCommand(query, connection);
                command.Parameters.Add(new OleDbParameter("SUMMARY_SPOD", Letter));
                command.Parameters.Add(new OleDbParameter("BUSNSS_ID", TrackingNumber));
                int rowUpdate = command.ExecuteNonQuery();
                Console.WriteLine($"{rowUpdate} row with {TrackingNumber} updated");
            }
            finally
            {
                if (command != null) { command.Dispose(); command = null; }
            }
        }
    }

I am not sure why it is still showing the error, does it have to do with the fact that Letter is a byte array?


Solution

  • I am not sure if this counts as solution, but it seems like that it has to do with OleDB.

    I never figured out why so I switched to Oracle.DataAccess.Client and changed all functions accordingly. After that, it worked.

    public void SaveSPODLetter(byte[] Letter, string TrackingNumber )
    {
        string query = @"UPDATE dcmnts 
                         SET SUMMARY_SPOD = :Summary_SPOD
                         where BUSNSS_ID = :BUSNSS_ID";
        OracleCommand command = null;
        string ConnString = ConfigurationManager.ConnectionStrings["My_db"].ToString();
    
        using (OracleConnection connection = new OracleConnection(BaseEncryptor.DecryptString(ConnString)))
        {
            try
            {
                if (connection.State != ConnectionState.Open)
                    connection.Open();
                command = new OracleCommand(query, connection);
                command.Parameters.Add(new OracleParameter("Summary_SPOD", Letter));
                command.Parameters.Add(new OracleParameter("BUSNSS_ID", TrackingNumber));
                command.ExecuteNonQuery();
                //Console.WriteLine($"{rowUpdate} row with {TrackingNumber} updated");
            }
            finally
            {
                if (command != null) { command.Dispose(); command = null; }
            }
        }
    }