c#向数据库中插入数据时出现乱码

shijixinmei888 2012-12-22 02:43:54

mycomm.CommandText = "insert into student values('" + textBox1.Text + "','" + textBox2.Text
+ "','" + textBox3.Text + "','" + textBox4.Text + "'," +
textBox5.Text + ")";

myconn.Open();
int cmdresults = mycomm.ExecuteNonQuery();
myconn.Close();
if (cmdresults == 1)
{
textBox1.ReadOnly = true; textBox2.ReadOnly = true; textBox3.ReadOnly = true;
textBox4.ReadOnly = true; textBox5.ReadOnly = true;
button2.Enabled = true; button3.Enabled = true;
ListViewItem newitem = listView1.Items.Add(textBox1.Text);
newitem.SubItems.Add(textBox2.Text);
newitem.SubItems.Add(textBox3.Text);
newitem.SubItems.Add(textBox4.Text);
newitem.SubItems.Add(textBox5.Text);
button1.Text = "添加";
MessageBox.Show("插入数据库成功!");
}
else
MessageBox.Show("插入数据库失败");
c#向mysql数据库中插入中文数据时显示为乱码,跪求高手指点,感激不尽!
...全文
312 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
shijixinmei888 2012-12-24
  • 打赏
  • 举报
回复
我知道怎么回事了,谢谢各位哈
Hauk 2012-12-23
  • 打赏
  • 举报
回复
数据库的机器是英文系统?

控制面板,区域和语言,设置非Unicode程序使用中文。
dl_newpage 2012-12-23
  • 打赏
  • 举报
回复
这个和数据库的版本有关安的是英文版的吧
njw1028 2012-12-23
  • 打赏
  • 举报
回复
MySQL字符集是gb2312?gbk?貌似要整成中文的。
whrspsoft3723 2012-12-22
  • 打赏
  • 举报
回复
kenengyuanyin: 1.数据库代码页 2.数据类型(nchar,varchar),试一下其他数据类型 3.驱动
shijixinmei888 2012-12-22
  • 打赏
  • 举报
回复
我试了,没用阿,我之前也用这个弄过
q33201682163 2012-12-22
  • 打赏
  • 举报
回复
试了,没用哦
jiangshun 2012-12-22
  • 打赏
  • 举报
回复
试试 mycomm.CommandText = "insert into student values(N'" + textBox1.Text + "',N'" + textBox2.Text + "',N'" + textBox3.Text + "',N'" + textBox4.Text + "'," + textBox5.Text + ")";

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧