I have a stored procedure that returns a string:
DECLARE @SqlStatement VARCHAR(MAX)
SELECT @SqlStatement =
COALESCE(@SqlStatement, '') + 'DROP TABLE [TMP].' + QUOTENAME(TABLE_NAME) + ';' + CHAR(13)
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'TMP'
PRINT @SqlStatement
I try to return the string like so:
var con = new SqlConnection(ConfigurationManager.ConnectionStrings["DBBASE"].ConnectionString);
using (var cmd = new SqlCommand("proSQL", con)
{
CommandType = CommandType.StoredProcedure
})
{
cmd.Parameters.Add("SqlStatement", SqlDbType.VarChar);
var returnParameter = cmd.Parameters.Add("@SqlStatement", SqlDbType.VarChar);
returnParameter.Direction = ParameterDirection.Output;
con.Open();
cmd.ExecuteNonQuery();
var result = returnParameter.Value;
}
When I run the code I get the error:
Procedure proSQL has no parameters and arguments were supplied
I am not sure what I am doing wrong. Can some please tell me how to get the output for a stored procedure in the format of a string?