超级奇怪的数据添加问题
我做的网站平时添加文章(中文)时,从来没有出过什么问题
可昨天我想添加一篇英文文章时,却无论如何也不可以,错误提示如下:
语法错误 (操作符丢失) 在查询表达式 ' '阿斯兰;的看法吉萨李开复I hate English, I don 't like English as I learn it.So however I learn English more than 8 years ' 中。
可当我添加的是少量的字母时,却又可以添加,真是郁闷死了,改了半天也没弄好
大家帮帮忙
我是用oledb连接的access数据库,下面是具体代码
public static void addArticle(string dbname,string title,string content,DateTime time,string writer,int classID)
{
OleDbConnection conn = DB.createConn(dbname);
title = title.Replace( "  ", " ");
OleDbCommand cmd = new OleDbCommand( "insert into article(articleTitle,articleContent,articleAddTime,articleWriter,classID) values( ' "+title+ " ', ' "+content+ " ', ' "+time+ " ', ' "+writer+ " ', "+classID+ ") ",conn);
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
}
------解决方案--------------------try:
content.Replace( " ' ", " ' ' ")
------解决方案--------------------title = title.Replace( " ' ", " ' ' ");
content= content.Replace( " ' ", " ' ' ");
------解决方案--------------------如果添加的内容中包含有单引号( '),肯定会出错的。办法是把单个 '换成双个 ',即:
title = title.replace( " ' ", " ' ' ")