开发者

c# How do i use a SqlParameters as table or column names?

How 开发者_开发技巧can i use a SQLParameter as as the table name and column name?

SELECT * FROM @TableName Where @ColumName=@Value

I get errors when i try to do something like that.


you'd have to use dynamic sql, which is generally not recommended.

Basically, you'd have to treat your sql like a string, append the variable values you want to include in the sql, then use exec sql to execute it.


Dynamic SQL -

declare @TableName as varchar(20)
declare @ColumnName as varchar(20)
declare @Value as varchar(20)
declare @dynsql as varchar(200)
--Set the values before
SET @dynsql='Select * from '+@TableName+'Where '+@ColumnName+'='+@Value
execute(@dynsql)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜