Click here to Skip to main content
15,867,986 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear all,

I have a table contain a column which holds arabic text , now I am sure that the col. char set is utf8 and the collection is utf8_unicode_ci and here is the connextion string:

Driver={MySQL ODBC 3.51 Driver};Server=XXX ;Port=3306;Database=XXX;User=root;password=XXX;Option=3;CharSet=UTF8;


When I read the table using MySql Workbench it display the arabic text very well
When I read it using Navicate Lite also display it fine
When I read it using my software C# + Vs2005 , it display strange letters (i tried textbox & a datagridview)

So what should I do? I checked a lot of google results and no way some sites said I must query "set names = utf8" before every query but I don't know how to insert it in the code since I am using TableAdapter and BindingSource so I don't write SQL command direct in the code.

thanks all
bye
Posted
Updated 9-May-19 22:55pm
v3

i might be late with this reply but i am posting this for future reference to other users
i also been looking for a way to insert arabic language into the MySQL database
so far i have been able to get the following solution to run properly on VB .net
currently i am using the MySQL connector .Net 6.4.4

first i have set my default collation for my database to cp1256 - default as windows uses this for arabic (according to this link[^])

then on the connection string put the CharSet to cp1256 similar to this
AccessData = New MySqlConnection("Server = xxx;Database = xxx;Uid = xxx;Pwd = xxx;CharSet=cp1256;")

now i just did a normal insert command with arabic letter and things worked OK
SQL = "INSERT INTO tbl1 (enVal, ArVal) VALUES ("test","arabic_characters");"

hope these information help
 
Share this answer
 
v2
Try use MySql Connector/.NET[^] it is a fully-managed ADO.NET driver for MySQL. The ODBC driver is an old one.
 
Share this answer
 
Try using 'N' before every name in your queries. for example:
INSERT INTO table values(N'arabic text').
 
Share this answer
 
v2
final use ODBC version 5 but u maybe facing that vs2005 will not be able to see tables easily
and much better don't use ODBC at all , but use the .net connector
 
Share this answer
 
try this...

public static string Server = "127.0.0.1";
public static string Database = "schemas";
public static string User = "root";
public static string Password = "";
public static string Port = "3306";
public static string charset = "utf8";

public static string constring = "Server=" + Server + ";" + "PORT=" + Port + ";" + "Database=" + Database + ";" + "Uid=" + User + ";" + "Password=" + Password + ";" +"charset=" + charset + ";";
public MySqlConnection cn = new MySqlConnection(constring);


I hope will help
 
Share this answer
 
Comments
Member 10026516 14-May-15 3:42am    
using charset=utf8 in coonection string but it not working
Member 14016308 10-Aug-21 17:03pm    
it worked perfectly , thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900