If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > MySQL, C# and UTF8 issues

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-07-09, 09:14
Andybitw Andybitw is offline
Registered User
 
Join Date: Sep 2009
Posts: 2
Question MySQL, C# and UTF8 issues

Hi,

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: Server=74.220.xxx.xxx;Port=3306;Database=xxx;Uid=x xx;Pwd=xxxx;CharSet=UTF8;"

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


Navicat
-------

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);
myCommand.ExecuteNonQuery();

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

What am I missing?


Thanks
Reply With Quote
  #2 (permalink)  
Old 09-10-09, 09:47
Andybitw Andybitw is offline
Registered User
 
Join Date: Sep 2009
Posts: 2
And the answer is:

Server=74.220.xxx.xxx;Port=3306;Database=xxx;Uid=x xx;Pwd=xxxx;charset=utf8;" [in lower case]
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On