none
DbDataAdapter.Fill() not selecting expected record when SelectCommand contains Unicode characters RRS feed

  • Question

  • I’m having trouble with the following code when the SelectCommand contains Unicode characters.  The data table is always empty after the fill despite SQL that should result in one record selected.

     

    We support both Oracle and SQL Server so this code is written referencing shared inherited classes but I’m currently testing using Oracle so 'command' is an OracleCommand and 'dataAdapter' is an OracleDataAdapter.

     

    The command.CommandText value is:

     

    SELECT state_prov_local.country_local,state_prov_local.description,state_prov_local.language_code,state_prov_local.state_prov_local FROM  state_prov_local  WHERE state_prov_local.state_prov_local = '浪呀'

     

     

    This returns one row when I run it directly against the database.

     

    Fill will load Unicode characters into the DataTable so it appears to only be a problem when the Unicode characters are used as part of the selection criteria.

     

    I also tried DataTable.Load and that didn’t work for me either.

     

    What am I doing wrong?  Is there anything else I should try?

     

     

    private void FillDatatable(IDbCommand command, DataTable dataTable, int maxRecords)

     

    {

          // Create the DataAdapter

          IDbDataAdapter dataAdapter = null;

          try

          {

                dataAdapter = GetDataAdapter();

                dataAdapter.SelectCommand= command;

     

                // Fill the DataTable

               (dataAdapter as DbDataAdapter).Fill(0, maxRecords, dataTable);                      

     

          }

          finally

          {

                IDisposable id = dataAdapter as IDisposable;

                if( id != null ) id.Dispose();

          }

    }

     

    Tuesday, September 23, 2008 2:23 PM

Answers

  • I would suspect that you're going to have to use a Command Parameter instead of attempting to insert the Unicode characters into the SQL string directly.

     

    Thursday, September 25, 2008 7:26 PM

All replies

  • I would suspect that you're going to have to use a Command Parameter instead of attempting to insert the Unicode characters into the SQL string directly.

     

    Thursday, September 25, 2008 7:26 PM
  • Thanks Paul.  You were correct.  This works if I add the Unicode characters as Parameters to the SelectCommand.

     

    Wednesday, October 1, 2008 1:03 PM