查看存储过程时,逻辑似乎是“做事”,然后是select 1 as add_success
. 如何add_success
在 C# 中检查该值?
代码
using (SqlConnection connection = new SqlConnection(_connectionString)) {
using (SqlCommand command = new SqlCommand("<sprocname>", connection)) {
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add(<a parameter>); // x10 or so
connection.Open();
var result = command.ExecuteNonQuery();
// result is always -1, despite the sproc doing everything it is supposed to do (modify a few different tables)
存储过程
// Do some stuff including inserts on a few different tables, then
INSERT INTO Table (field1, field2)
VALUES (@Val1, @Val2)
SELECT 1 AS add_success
它似乎做的一切都是正确的,但默认的返回ExecuteNonQuery
是受影响的行,-1
即使所有的操作似乎都成功完成了。
我还尝试添加一个带有名为的返回值的参数,add_success
但这@add_success
似乎也不起作用。
如何将值从存储过程返回到 C#?