插入"???"从波斯语的C#代码发布时,在mysql数据库中 [英] Insert "????" in mysql database when post from c# code in Persian language

查看:49
本文介绍了插入"???"从波斯语的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();

和来自mysql的图片

请帮助我解决此问题;)

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;

这篇关于插入"???"从波斯语的C#代码发布时,在mysql数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆