insert 时的数据问题。

Rossetti 2003-12-12 10:36:54
//col1 is integer
//col2 is string
//col3 is string
string _col2 = "(我爱我家)" ;
string _col3 = "我爱我家";
connect = new System.Data.SqlClient.SqlConnection( connectionstring ) ;
string cmdtext = "insert into tab_1(col1,col2,col3) values(1,'" + _col2 + "','" + _col3 + "')";
connect.Open() ;
System.Data.SqlClient.SqlCommand scmd1 = new System.Data.SqlClient.SqlCommand( cmdtext , connect ) ;
scmd1.ExecuteNonQuery() ;
connect.Close() ;
/// 问题时这样的,当 _col2 或 _col3 的数据当中存在中文标点符号的时候,出现错误。为什么?
...全文
58 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lfkool 2003-12-12
  • 打赏
  • 举报
回复
UP
tommyhuanglei 2003-12-12
  • 打赏
  • 举报
回复
up
tommy
nedvedlh 2003-12-12
  • 打赏
  • 举报
回复
有可能类型发生错误!
nedvedlh 2003-12-12
  • 打赏
  • 举报
回复
string cmdtext = "insert into tab_1(col1,col2,col3) values('1','" + _col2 + "','" + _col3 + "')";
tommyhuanglei 2003-12-12
  • 打赏
  • 举报
回复
你设置的什么类型!
brightheroes 2003-12-12
  • 打赏
  • 举报
回复
设置你的数据库的对应字段的类型为nvarchar,然后看看还有没有错误

110,561

社区成员

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

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

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