日期:2014-05-19  浏览次数:20515 次

请问为什么这里有个replace,为什么要代替这个字段???
"select   *   from   admin   where   admin_name= ' "   +   text1.Text.Replace( " ' ",   " ' ' ")   +   " '   and   admin_pwd= ' "   +   text2.Text.Replace( " ' ",   " ' ' ")   +   " '   ";

如题

------解决方案--------------------
'是关键字符,应该是防止sql注入
------解决方案--------------------
因为'在数据库是分隔字符串的,所以要转换一下
------解决方案--------------------
如果你使用SQL Server,那么这是遵从SQL Server语法定义。

可以参靠考:

http://www.google.com/search?as_q=&hl=zh-CN&newwindow=1&rls=com.microsoft%3Aen-US&num=10&btnG=Google+%E6%90%9C%E7%B4%A2&as_epq=%E5%8D%95%E5%BC%95%E5%8F%B7&as_oq=&as_eq=&lr=&as_ft=i&as_filetype=&as_qdr=all&as_occt=any&as_dt=i&as_sitesearch=msdn2.microsoft.com%2Fzh-cn&as_rights=

实际上,你应该首先自己问自己“如果text1.Text中包含单引号会不会出错?”,这样你的程序才比较具有质量。如果自己要求不高,再加上没有非常全面的测试,那么软件那个不加“replace”的软件的最终用户就倒霉了。