Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# MySQL
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 9-May-11 2:25am
Adore C++12.8K
Edited 9-May-11 3:15am
Nagy Vilmos265.2K
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try use MySql Connector/.NET[^] it is a fully-managed ADO.NET driver for MySQL. The ODBC driver is an old one.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try using 'N' before every name in your queries. for example:
INSERT INTO table values(N'arabic text').
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

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
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 352
1 OriginalGriff 344
2 Abdul Samad KP 145
3 CPallini 140
4 Richard MacCutchan 110
0 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,680
2 CPallini 4,850
3 George Jonsson 3,454
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 28 Nov 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100