Question

Is there a way to get the parameter collection from SqlCommand when CommandType = Text?

For instance:

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...

I want a way to get a parameter collection with [@Param1,@Param2]... I don't know the sql queries (they are dynamic) and I want to get the parameters for my application to create them as input controls.

I can't do this with SqlCommandBuilder.DeriveParameters(command), because it only works with stored procedures.

Thank you!

Was it helpful?

Solution

No - until SQL Server parses the command, it's just a string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top