1

有没有办法从 CommandType = Text 获取SqlCommand参数集合

例如:

string MyDinamicSql = @"SELECT * FROM USERS where USERName = @Param1 and USERLogin=@Param2";
SqlCommand comand = connection.CreateCommand();
comand.CommandText = MyDinamicSql;
comand.CommandType = System.Data.CommandType.Text;

//Do something for fill comand.Parameters from MyDinamicSql...

我想要一种使用 [@Param1,@Param2] 获取参数集合的方法...我不知道 sql 查询(它们是动态的),我想获取我的应用程序的参数以将它们创建为输入控件。

我不能这样做SqlCommandBuilder.DeriveParameters(command),因为它只适用于存储过程。

谢谢!

4

1 回答 1

2

否 - 在 SQL Server 解析命令之前,它只是一个字符串。

于 2012-01-27T18:30:49.940 回答