MySql和C#以及阿拉伯语 [英] MySql and C# and arabic
问题描述
亲爱的,
我有一个表格,其中包含一个包含阿拉伯语文本的列,现在我确定col。 char set是 utf8
,集合是 utf8_unicode_ci
,这里是连接字符串:
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;
当我使用MySql Workbench阅读表格时,它非常好地显示阿拉伯语文本
当我读到它使用Navicate Lite也显示它很好
当我使用我的软件C#+ Vs2005阅读它时,它显示奇怪的字母(我试过文本框和数据网格视图)
那我该怎么办?我检查了很多谷歌搜索结果,并且没有办法说我必须在每次查询之前查询set names = utf8
但我不知道如何将其插入代码,因为我使用 TableAdapter
和 BindingSource
所以我不在代码中直接编写SQL命令。
谢谢所有
再见
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
推荐答案
我可能会迟到这个回复但是我发布此信息以供将来参考其他用户
i也一直在寻找将阿拉伯语言插入MySQL数据库的方法
到目前为止我已经能够得到以下解决方案在VB上正常运行.net
目前我正在使用MySQL连接器.Net 6.4.4
首先我设置了我的默认排序规则对于我的数据库到cp1256 - 默认为Windows使用它为阿拉伯语(根据这个链接 [ ^ ])
然后在连接字符串上将CharSet放到与此类似的cp1256
AccessData = New MySqlConnection(Server = xxx; Database = xxx; Uid = xxx ; Pwd = xxx; CharSet = cp1256;)
现在我只用阿拉伯字母做了一个正常的插入命令,工作正常好
SQL =INSERT INTO tbl1(enVal,ArVal)VALUES(test,arabic_characters);
希望这些信息能帮助
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
>
尝试使用 MySql Connector / .NET [ ^ ]它是一个完全托管的MySQL ADO.NET驱动程序。 ODBC驱动程序是旧驱动程序。
Try use MySql Connector/.NET[^] it is a fully-managed ADO.NET driver for MySQL. The ODBC driver is an old one.
在查询中的每个名称前尝试使用N。例如:
INSERT INTO表值(N'arabic text')。
Try using 'N' before every name in your queries. for example:
INSERT INTO table values(N'arabic text').
这篇关于MySql和C#以及阿拉伯语的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!