插入"???"从波斯语的C#代码发布时,在mysql数据库中
当我使用c#中的mysql实体在mysql数据库中插入帖子时,我遇到了问题.插入的记录中的波斯字母转换为"????"但是当我从数据库中读取波斯语内容(之前存储的内容)时,它们显示得很好.
i have a problem when i insert a post in mysql database with mysql entity in c#. The persian letters in inserted record convert to "????" but when i read from database persian contents (that stored before) they're shown very well.
我的表排序规则是UTF8mb4_unicode_520_ci,当我插入来自wordpress的帖子时,显示得很好,但是当我在代码中尝试相同时,我遇到了指定的问题
My table collation is UTF8mb4_unicode_520_ci and when I insert post from wordpress is shown well but when I try the same in my code I have the specified problem
这是我要插入数据库的代码:
Here is my code for inserting in database:
wp_posts post = new wp_posts
{
post_author = 1,
post_date = DateTime.Now,
post_date_gmt = DateTime.Now,
post_content = "<h2>" + txtPersianContent.Text + "</h2>",
post_title = txtPersianTitle.Text,
post_excerpt = "None",
post_status = "publish",
comment_status = "open",
ping_status = "open",
post_password = "",
post_name = txtName.Text,
post_modified = DateTime.Now,
post_modified_gmt = DateTime.Now,
guid = txtGUID.Text,
to_ping = "None",
pinged = "None",
post_content_filtered = "None",
post_parent = 0,
menu_order = 0,
post_type = "post",
post_mime_type = "",
comment_count = 0
};
db.wp_posts.Add(post);
db.SaveChangesAsync();
请帮助我解决此问题;)
Please help me to fix this problem ;)
检查您的连接字符串!您应该在与mysql的连接中指定字符集:
check your connection string! You should specify Character Set with your connection to mysql:
Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword; CharSet=utf8;