原来数据库字符集是默认的,显示一切正常,后来由于数据库服务器将默认的字符集配置成了utf-8导致显示的中文都成了?。
请问客户端这边该如何修改才能正常显示中文?是否能在连接字符串中加入指定字符集的参数?
具体环境如下:
delphi7.0
mysql-odbc-3.51.12
mysql5.0.18-win32
ado连接字符串'Provider=MSDASQL.1;Password=DBServerPassWord;Persist Security Info=True;User ID=DBServerUserName;Extended Properties="DATABASE=C_DBName;DRIVER={MySQL ODBC 3.51 Driver};OPTION=0;PWD=DBServerPassWord;PORT=0;SERVER='+DBPath+';UID=DBServerUserName";

解决方案 »

  1.   

    如果你用dbgrid显示,应该显示不出来。因为VCL组件不支持。
      

  2.   

    dbgrid我倒没有试,但是下拉框里都是?了。是所有的vcl组件都不支持utf-8?有没有解决方法?
      

  3.   

    vcl都不支持,你可以写个函数转换一下。//Utf8存、取
    procedure TForm1.Button1Click(Sender: TObject);
    var
      S: string;
    begin
      //存
      with TMemoryStream.Create do try
        S := #$EF#$BB#$BF;
        Write(S[1], Length(S));
        S := AnsiToUtf8(Memo1.Text);
        Write(S[1], Length(S));
        Position := 0;
        SaveToFile('c:\temp\temp.txt');
      finally
        Free;
      end;
    end;procedure TForm1.Button2Click(Sender: TObject);
    var
      S: string;
    begin
      //取
      if not FileExists('c:\temp\temp.txt') then Exit;
      with TMemoryStream.Create do try
        LoadFromFile('c:\temp\temp.txt');
        SetLength(S, Size);
        Read(S[1], Length(S));
        if Copy(S, 1, 3) <> #$EF#$BB#$BF then Exit;
        Memo2.Text := Utf8ToAnsi(Copy(S, 4, MaxInt));
      finally
        Free;
      end;
    end;
      

  4.   

    你去找TntUnicodeControls组件。不过我没试过,不知道是否可行。