时间:2019-05-06 标签:c#mysqlAddWithValueunicode [英] c# mysql AddWithValue unicode

查看:34
本文介绍了时间:2019-05-06 标签:c#mysqlAddWithValueunicode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在使用 C# 和 MySQL.我试图在互联网上搜索一天,以找出为什么我不能使用 AddWithValue 方法添加 unicode 字符,因为当我在 MySQL 中手动添加它时,它可以工作!但是回到带有 MySQL 连接器的 C# 代码中,用于 .NET 它不起作用.除了unicode字符都可以.

I'm working with C# and MySQL now. I've tried to search around the internet for day to find out why I can't use AddWithValue method to add unicode characters because when I manually add it in MySQL, it works! But back in the C# code with MySQL connector for .NET it doesn't work. Other than the unicode characters is fine.

cmd.CommandText = "INSERT INTO tb_osm VALUES (@id, @timestamp, @user)";
cmd.Parameters.AddWithValue("@id", osmobj.ID);
cmd.Parameters.AddWithValue("@timestamp", osmobj.TimeStamp);
cmd.Parameters.AddWithValue("@user", osmobj.User);
cmd.ExecuteNonQuery();

例如:osmbj.User = "ສະບາຍດີ",就会是"???????"在数据库中.请T^T

For example: osmbj.User = "ສະບາຍດີ", it will be "???????" in the database. Please T^T

推荐答案

此链接对您有帮助吗?

在 MySql 中读/写 unicode 数据

基本上它说,你应该用 charset=utf8 附加你的连接字符串;

Basically it says, you should append your connection string with charset=utf8;

像这样:id=my_user;password=my_password;database=some_db123;charset=utf8;

Like so: id=my_user;password=my_password;database=some_db123;charset=utf8;

这篇关于时间:2019-05-06 标签:c#mysqlAddWithValueunicode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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