4

I have following TSQLDataSet in my Delphi 7 application. It is fetching 2 fields (ID and Name) from table MyTable.

object SQLDataSet: TSQLDataSet
    GetMetadata = False
    CommandText = 'select * from MyTable'
    MaxBlobSize = -1
    Params = <>
    SQLConnection = mySQLConnection

    object SQLDataSetID: TIntegerField
      FieldName = 'ID'
      ProviderFlags = [pfInUpdate, pfInWhere, pfInKey]
      Required = True
    end
    object SQLDataSetNAME: TStringField
      FieldName = 'NAME'
      Required = True
      Size = 50
    end
end

When I migrated to the Delphi XE4, I am getting following error:

class EDatabaseError with message 'SQLDataSet: Type mismatch for field 'NAME', expecting: String actual:WideString'

What could be the possible cause of this problem and how should I get rid of it?

Note: I am using firebird 2.5.2.

Guillem Vicens
  • 3,936
  • 30
  • 44
  • 4
    Try changing `TStringField` to `TWideStringField` – ZigiZ Sep 24 '13 at 08:16
  • @ZigiZ - Thanks for your comments. This will solve the problem but why should I do it. I followed a link http://isatsara.blogspot.in/2012/01/delphi-2010-expecting-string-actual.html where this suggestion was given but I did not get his explanation. Also this one http://forums.devart.com/viewtopic.php?t=22080 . How should I justify this change to others? –  Sep 24 '13 at 08:18
  • What is the type in the Firebird database for the `NAME` field of table `MyTable`? – Jeroen Wiert Pluimers Sep 24 '13 at 08:41
  • @JeroenWiertPluimers - It is of varchar(50) type in firebird –  Sep 24 '13 at 09:00
  • This sounds like an encoding issue, so please update your answer with: the character set encodings of your database, table and TSQLConnection. The easiest is to have a small DDL of a database plus single table, and the .DFM + .PAS part of a very simple form + connection + dataset. That way we can reproduce your problem. What I think happens is that your database is using some form of Unicode encoding, and the Delphi side of things thinks the encoding is UTF-16 hence expecting `WideString`. – Jeroen Wiert Pluimers Sep 24 '13 at 09:16

1 Answers1

1

Change the TStringField to TWideTStringfield

object SQLDataSet: TSQLDataSet
    GetMetadata = False
    CommandText = 'select * from MyTable'
    MaxBlobSize = -1
    Params = <>
    SQLConnection = mySQLConnection

    object SQLDataSetID: TIntegerField
      FieldName = 'ID'
      ProviderFlags = [pfInUpdate, pfInWhere, pfInKey]
      Required = True
    end
    object SQLDataSetNAME: **TWideStringField**
      FieldName = 'NAME'
      Required = True
      Size = 50
    end
end
Christian Garbin
  • 2,512
  • 1
  • 23
  • 31