先谢过LS各位。 我将Mysql的编码设置为utf-8: string connstr = "Data Source=test;User Id=root;Password=806591;charset=utf-8" 插入中文表还是不行,英文表是可以的,mysql所有VARIABLES LIKE 'character_set_%'及VARIABLES LIKE 'collation_%'都设置成utf8,gbk2312也设置过了,都没有效果。 如果按照LS将 成绩表 两端加``符号,错误为table test."一堆乱码显示" doesn't exist.
如果连接字符串里"charset=utf-8"或"charset=gb2312"或者根本不设置,出现的错误都一样,如下. MySQLDriverCS Exception: MySQLDriverCS Error: wrong query. You have an error in your SQL syntax; check the manul that corresponds to your MySQL server version for the right syntax to use near '哈喽 VALUES (10)' at line 1 INSERT INTO 哈喽 VALUES (10)";另外,MYSQL版本5.0字符串:string query = "INSERT INTO 哈喽 VALUES (10)"; VS2005里执行代码,英文表都没有问题.期待解答。
如.PHP中.加入
header('Content-Type:text/html;charset=utf-8');UTF-8就是编码格式.另外文件也要存为相同格式.(记事本的话就是另存为.然后格式选UTF-8)
character_set_results=
查下手册吧
此项要与mysql默认的编码格式一致。
用记事本打开 另存为,选择编码格式。不过,这条sql语句最好写成:
string query = "INSERT INTO `成绩表` VALUES (2,'lohha','jacky')"; 看好了,成绩表两面加的不是 单引号“'”, 而是 “`”
我将Mysql的编码设置为utf-8: string connstr = "Data Source=test;User Id=root;Password=806591;charset=utf-8"
插入中文表还是不行,英文表是可以的,mysql所有VARIABLES LIKE 'character_set_%'及VARIABLES LIKE 'collation_%'都设置成utf8,gbk2312也设置过了,都没有效果。
如果按照LS将 成绩表 两端加``符号,错误为table test."一堆乱码显示" doesn't exist.
MySQLDriverCS Exception: MySQLDriverCS Error: wrong query. You have an error in your SQL syntax; check the manul that corresponds to your MySQL server version for the right syntax to use near '哈喽 VALUES (10)' at line 1 INSERT INTO 哈喽 VALUES (10)";另外,MYSQL版本5.0字符串:string query = "INSERT INTO 哈喽 VALUES (10)";
VS2005里执行代码,英文表都没有问题.期待解答。
2、在执行sql语句前,先执行:set names 'utf8' 怎么执行,楼主会吧。
string query = "set names 'utf8' "; 执行 query。
3、query = "INSERT INTO `成绩表` VALUES (2,'lohha','jacky')";
4、再执行 query 语句。这样试试看。