写入数据内存溢出的错误ErrorCode=2147217900解决

近日客户pygaosha反映,当mdb写入数据时候,有错误出现。

操作符丢失...Source="Microsoft JET Database Engine ErrorCode=-2147217900     可以看资料看到是 数据内存溢出的错误

经过我反复调试和实践,并且在网上找了资料,终于解决了
如:原来是string content = Editor1.Text;  要改成string content = Editor1.Text.Replace ("'","''"); 这是因为:

sql = "insert into New (BigClassID,Title,Content,Author,AddTime,ReadCishu,news_pic,newspic_link,flash_http_type) Values(" + classid + ",'" + title + "','"+content + "','" + author + "','" + DateTime.Now + "',1,'"+uploads_pic_hhw +"','ztView.aspx?id=','"+TextBox2 .Text+"')";

如果文本框中含有单引号( '),这样写是有问题的,所以要么将单引号替换成两个单引号( ' '),要么用传参数的方法。

另外在该小项目中发现了不少小的漏洞。例如上传图片时:if (type == "gif" || type == "bmp" || type == "jpg" || type == "GIF" || type == "BMP" || type == "JPG")//允许类型

则需要看后缀名分大小写的。我很大意,一时间只写了小写的.以后不要粗心了。

 

原文地址:https://www.cnblogs.com/pyman/p/1970812.html