What is the difference between odbcparameter and oledbparameter when adding char type values?

107 views Asked by At

I'm migrating from Oracle to Tibero database using C#.

Issue is when adding parameter of "CHAR" type using OleDbParameter, data can not be retrieved unless it is filled with following spaces according to DB column size.

(Using OracleParameter or using OdbcParameter, it is possible to query normally without filling empty space as the actual column size)?

String sSQL = @"SELECT *
                          FROM V_PROD_MA
                         WHERE CAR_TYPE = :CAR_TYPE
                           AND BODY_NO  = :BODY_NO";

        OleDbDataAdapter adapter = null;
        //OracleDataAdapter adapter = null;
        DataTable         table   = new DataTable();

        try
        {
            Open();

            adapter = new OleDbDataAdapter(sSQL, Connetion);

            adapter.SelectCommand.Parameters.Add("CAR_TYPE", OleDbType.Char, 4).Value = sCarType;
            adapter.SelectCommand.Parameters.Add("BODY_NO", OleDbType.Char, 6).Value = sBodyNo;

            adapter.Fill(table);
        }

Above is a test source code and when I set sCarType = 'D0F ' then data is retrieved, but when I set sCarType = 'D0F' data is not retrieved.

Actual column size is char(4).

You might suggest to change the SQL WHERE statement like trim(car_type), but we have about 2,000 SQL statements to change, so we want to avoid that kind of solution.

And also we use a framework for wrapping each SQL command, parameters and the framework doesn't have information of column size to fill with empty spaces.

Is there any other way to avoid this kind of issue?

0

There are 0 answers