sql语句中的变量表示

sitoto 2004-07-19 06:09:28
T1是上一页传的text值到当前页 Dim D1 =Request.form("T1")
在sql查询语句中如何表示变量T1如:”select * from table where item=D1“
这个item在access中是文本格式,该如何写这句sql语句?谢谢
...全文
211 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
sitoto 2004-07-20
  • 打赏
  • 举报
回复
我试了一下将D1赋值为 "';create table asdf(id int)'" 结果攻击不能成功,它好像把“;”当作是结束符,是不是我使用的是access的原因?
另外我改为zhanqiangz(闲云野鹤)的
cmd.parameters.add("@item",request.form("t1").tostring)发现也可以使用,谢谢!
这条注入式攻击的语句是不是这样写的:
select * from table where item='""';create table asdf(id int);
langmafeng 2004-07-20
  • 打赏
  • 举报
回复
最好用参数,其一可以防止注入式攻击,其二对特殊字符(如'等)不用自己处理了
sitoto 2004-07-20
  • 打赏
  • 举报
回复
我对安全性不了解,
net_lover(孟子E章)的
"select * from table where item='" +D1 + "'" 确实可行,如果这个语句查询有会遭到攻击,是不是要用
zhanqiangz(闲云野鹤)
dim strcmd as string="select * from table where item=@item"
dim cmd as new sqlcommand(strcmd,cnn)
cmd.parameters.add("@item",request.form("t1").tostring) ???


sitoto 2004-07-20
  • 打赏
  • 举报
回复
谢谢各位的指点!让我获益匪浅啊!
mooniscrazy 2004-07-19
  • 打赏
  • 举报
回复
万万不可用这样的,"select * from table where item='" +D1 + "'"
因为会被人插入Sql攻击
比如D1="';create table asdf(id int)--";
he_hawk 2004-07-19
  • 打赏
  • 举报
回复
很简单

SQL中所有字符串查询都要加单引号的
日期的也加
数值的不用加
maxwelling 2004-07-19
  • 打赏
  • 举报
回复
"select * from table where item='" +D1 + "'"
数字请用:
"select * from table where item=" +D1 + ""
Overriding 2004-07-19
  • 打赏
  • 举报
回复
dim strcmd as string="select * from table where item=@item"
dim cmd as new sqlcommand(strcmd,cnn)
cmd.parameters.add("@item",request.form("t1").tostring)
besttian 2004-07-19
  • 打赏
  • 举报
回复
"select * from table where item="+D1
孟子E章 2004-07-19
  • 打赏
  • 举报
回复
Dim D1 as String =Request.form("T1").ToString()
"select * from table where item='" +D1 + "'"
孟子E章 2004-07-19
  • 打赏
  • 举报
回复
"select * from table where item='" +D1 + "'"

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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