I am making a windows service to be able to run operations on a sql server database (insert, edit, etc) and invoke Stored Procs.
However, is there a way for me to know the type of the SP? When invoking from C#, I need to knof if it is returning 1 value, or more, or none (so I can use executereader, scalar, etc)?
Thanks
SqlCommand.ExecuteNonQuery(). But it’s valid to run it asSqlCommand.ExecuteReader(). The only difference is that the first call toDataReader.Read()returnsfalsefor a stored procedure that does not return a resultset.SqlCommand.ExecuteReader(). The first call toDataReader.Read()will returntrue.So you can use
ExecuteReaderin all three scenarios.Though it seems unnecessary for your question, you can retrieve meta-data for the resultset using the fmtonly option. The setting causes the statement to return the column information only; no rows of data are returned. So you could run:
Executing this as a
CommandTextfrom C#, you can examine the column names the stored procedure would return.To verify that a stored procedure run in this way does not produce any side effects, I ran the following test case:
This did not return any rows. So the format-only option makes sure no actual updates or inserts occur.