Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2009

    Question Unanswered: MySQL, C# and UTF8 issues


    I have a database on my website that's 100% UTF8.

    My PHP pages can read, display and set Chinese values well.

    I have a MySQL connection on my XP64: Encoding 65001 UTF8

    And there's database that's utf8 & utf8_general_ci

    In that, there's a table: field sSPzht: utf8 & utf8_general_ci

    When my C# app gets Chinese text from the web, and updates the field sSPzht: I see "????".

    This is an encoding issue. But where?

    More information:

    MySQL connection strings:

    Web:;Port=3306;Database=xxx;Uid=x xx;Pwd=xxxx;CharSet=UTF8;"

    XP64: Server=localhost;Port=3306;Database=smoreports;Uid =root;Pwd=xxxx;CharSet=UTF8;"


    Using Navicat: I can type Chinese into the sSPzht field successfully.

    Using the the C# code...

    string idSP = "2";
    string dat = SMOMain.GetHMData(tbl, "sSPzht", "idSP=" + idSP, true);
    sql = "UPDATE " + tbl + " SET sSPzht='" + dat + "' WHERE idSP=" + idSP + ";";
    // Set data
    lbl1.Text = dat;
    txt1.Text = dat;

    ..Will put the Chinese into a TextBox and label that is displayed perfectly.

    Using Navicat: I can copy the Chinese from the TextBox on a C# form and paste it into my sSPzht field succesfully.

    Here's my issue:

    sql = "UPDATE " + tbl + " SET sSPzht='" + dat + "' WHERE idSP=" + idSP + ";";

    MySqlCommand myCommand = new MySqlCommand(sql, myConnection);

    The above code only puts ???? into the sSPzht field.

    What am I missing?


  2. #2
    Join Date
    Sep 2009
    And the answer is:;Port=3306;Database=xxx;Uid=x xx;Pwd=xxxx;charset=utf8;" [in lower case]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts