I've written a query parser that should create a SqlCommand and execute a stored procedure. The query for the stored procedure can come in many forms, including this one:
exec dbo.sp_StoredProcedureName 1599800
In this case, I create the SqlParameter this way:
var param = new SqlParameter() { Value = paramValue };
I get an error stating that '@Parameter1' is not a parameter for procedure sp_StoredProcedureName.
Is there a way I can do this without running it as a standard query? I'd like to keep it consistent and build the SqlCommand as a StoredProcedure type if possible.
I was thinking maybe I could reflect the parameter names of the stored proc first, but wondering if there's another approach.