Search code examples
c#oracle-databaseodp.nettableadaptersystem.data.oracleclient

Replacing TableAdapters with Oracle.DataAccess.Client (ODP.NET)


I have a legacy DAL with like 100 TableAdapters (DataSet xsd) but because we got new servers with Oracle client 12c I had to made the switch to the Oracle.DataAccess.Client (ODP.NET) from the old deprecated System.Data.OracleClient.

The only problem I have now is that I always get an error: ORA-01008: Not all variables bound when calling the Table Adapters.

I read that I have to set BindByName to true in OracleCommand for each TableAdapter. But how can I do that when the only place where OracleCommand is used is in the designer of the TableAdapter itself?

Is there some way to do this without extending each TableAdapter, because I have like 100 of them.


Solution

  • What I did was I extended each TableAdapter and created a new SetBindByName() method, where I forced BindByName = true on the OracleCommand collection.

    Like so...

    public partial class V_CUSTOMER_GLOBALTableAdapter
    {
        public void SetBindByName(bool value = true)
        {
            foreach (Oracle.DataAccess.Client.OracleCommand cmd in this.CommandCollection)
            {
                cmd.BindByName = value;
            }
        }
    }
    

    Then when I created an instance of the TableAdapter, I called the new SetBindByName() method.

    V_CUSTOMER_GLOBALTableAdapter ta = new V_CUSTOMER_GLOBALTableAdapter();
    ta.SetBindByName(true);