create PROCEDURE [dbo].[Tradeinfo_Getinfo]
@username varchar(50)=null,
@active int=null,
@top int=10000
AS
declare @sqlwhere nvarchar(1000)
declare @sql nvarchar(1000)
set @sqlwhere='' if(@username is not null)---@username
set @sqlwhere=@sqlwhere +' and username='+@username+''
if(@active is not null)---@active
set @sqlwhere=@sqlwhere+' and active='+str(@active)+''
set @sql='SELECT top '+str(@top)+' price,id FROM Tradeinfo where 1=1 '+@sqlwhere+' '
exec(@sql)提示列名XXX无效。XXX是输入的username的值
@username varchar(50)=null,
@active int=null,
@top int=10000
AS
declare @sqlwhere nvarchar(1000)
declare @sql nvarchar(1000)
set @sqlwhere='' if(@username is not null)---@username
set @sqlwhere=@sqlwhere +' and username='+@username+''
if(@active is not null)---@active
set @sqlwhere=@sqlwhere+' and active='+str(@active)+''
set @sql='SELECT top '+str(@top)+' price,id FROM Tradeinfo where 1=1 '+@sqlwhere+' '
exec(@sql)提示列名XXX无效。XXX是输入的username的值
解决方案 »
- 问一个关于httpHandler处理页面的问题,大家来看看,有点小急哦!(已经是所有的分了)
- 怎么样在后台取gridview表头控件?
- 问大家一个treeview显示的问题
- Com组件使用的问题!非常急,感谢各位帮忙
- 求学习VS.NET 2005 的资料
- 为什么我的提交动作在本机可以执行,上传到虚拟主机上就执行不了了呢?急死了!
- 三层里业务层和数据层都应该写点什么?
- 用iss只能打开html,不能调试asp文件
- 学习
- ASP.NET 与VISIO接口?????????????????????????
- 两个域名指向相同的程序目录,使用其中一个域名操作时更新的缓存在另一个域名下看还是没更新,不同步
- gridview 中分页的问题/
set @sqlwhere=@sqlwhere +' and username='''+@username+''''
replace(@sqlwhere,'''',''''''')+' '
set @sqlwhere=@sqlwhere+' and active='+str(@active)+'' 这个没错是因为是数字,字符要加' where name='非'
@username varchar(50)=null,
@active int=null,
@top int=10000
AS
declare @sqlwhere nvarchar(1000)
declare @sql nvarchar(1000)
set @sqlwhere='' if(@username is not null)---@username
set @sqlwhere=@sqlwhere +' and username='''+@username+''''
if(@active is not null)---@active
set @sqlwhere=@sqlwhere+' and active='+str(@active)+''
set @sql='SELECT top '+str(@top)+' price,id FROM Tradeinfo where 1=1 '+@sqlwhere+' '
exec(@sql)
create procedure dbo.tradeinfo_getinfo
@username varchar(50)=null,
@active int=null,
@top int=10000
as
declare @sqlwhere nvarchar(1000);
declare @sql nvarchar(1000);
set @sqlwhere = '';
if(@username is not null)
set @sqlwhere=@sqlwhere + 'and [username]=@tusername ';
if(@active is not null)
set @sqlwhere=@sqlwhere + 'and [active]=@tactive ';
set @sqlwhere=' where 1=1 '+@sqlwhere;
set @sql = 'select top '+convert(nvarchar(15),@top)+ '[price],[id] from [tradeinfo]'+@sqlwhere
declare @param nvarchar(400)
set @param='@tusername nvarchar(50),@tactive int';
execute sp_executesql @sql,@param,@tusername=@username,@tactive=@active;建议不要用你的这种SQL拼接(有注入漏洞),用我的这种用@TUSERNAME占位,后面用@TUSERNAME=@USERNAME参数替换的方式。