ODBC/TSQLQuery:TWideStringField.AsString returns '???' lazarus / 16-Databases ---------------------------------------------------------------------- tk · 2009-10-01 10:49 Hi, I'm testing a connection to my MSSQL database via Lazarus TODBCConnection/TSQLQuery/TSQLTransaction. I cannot display my nvarchar columns properly. For example in my TDBEdit I get '???' for these columns and any record. I discovered the problem is located at TWideStringField.AsString which returns '???' instead of valid text. The same result I get for TWideStringField.AsWideString. Has anybody similar experience? Thx ---------------------------------------------------------------------- Zoran · 2009-10-01 16:53 Try using UTFEncode function. Perhaps putting the Field's OnGetText event would be the best for you. Something like this: Quoteprocedure TForm1.SQLQuery1Field1GetText(Sender: TField;   var aText: string; DisplayText: Boolean); begin   aText := UTF8Encode(Sender.AsString); end; After that you can use Field1.AsString normally. ---------------------------------------------------------------------- tk · 2009-10-01 21:21 I tried now and didn't get expected results. It seems to be a FPC problem. The dataset (or something else) assigns a TWideStringField for a table field that is natively not UTF16. I tried the following code and got expected text in S for this case: Code: [Select]var   S: string; ... SetLength(S, AField.DataSize); AField.GetData(@S[1], True); ... Of course I cannot use this because in other cases where fields are natively in UTF16 format this would not work. Perhaps I should place new issue in FPC bugtracker later. ---------------------------------------------------------------------- Zoran · 2009-10-02 07:00 Did you look in the LConvEncoding unit? Apart from functions for converting particular character sets, in that unit you can also find the function named GuessEncoding. I haven't tried this function, maybe it can help you determine whether the string you got from database is UTF16 or not, and if not, which encoding it is. I don't know... I hope that someone better experienced in this than me will have to say something to help you. ---------------------------------------------------------------------- calvarez · 2009-11-06 13:04 I'm trying to connect to a MSSQL server from Linux. You could connect mssql from linux? Thanks for your time.