SqlCommand.Parameter属性的作用是利用参数化的方法来调用T-SQL语句或者存储过程,它相较于传统的字符串拼接的优势是明显的:(1)可以减少诸如string Strsql = "select * from CM_Users where CM_User_id='" + nid + "' and CM_User_password='" + pwd + "'";的运用,代码可读性高;(2)可以在一定程度上防范SQL注入,安全性高。

 

SqlCommand.Parameter属性的add()方法的作用是:添加参数到SqlParameterCollection 参数集,add里面的第一个参数是要添加的参数名,第二个参数是参数的数据类型。举两个例子如下:

例1:

例2:

相关文章:

  • 2021-11-11
  • 2021-11-11
  • 2021-11-27
  • 2021-11-11
  • 2021-08-09
  • 2021-12-03
猜你喜欢
  • 2021-12-22
  • 2022-01-01
  • 2021-06-04
  • 2021-12-22
  • 2021-11-17
相关资源
相似解决方案