我没有看到任何OUTPUT
条款只是还没有 - 但如果你没有拥有它,你需要做的仅仅是运行此存储过程,就好像它返回的结果集(从SELECT
声明):
using (SqlConnection conn = new SqlConnection(-your-connection-string-here-))
using (SqlCommand cmd = new SqlCommand("[xyz].[stored_proc]", conn))
{
cmd.CommandType = CommandType.StoredProcedure;
conn.Open();
// execute your UPDATE statement with an OUTPUT clause into a SqlDataReader
using(SqlDataReader reader = cmd.ExecuteReader())
{
// read the values returned from the OUTPUT clause
while(reader.Read())
{
int insertedID = reader.GetInt32(0);
// do something with those values....
}
}
conn.Close();
}
这是假设你的UPDATE语句存储过程里面会是这个样子:
UPDATE ...
OUTPUT Inserted.ID -- or something else....
SET input1 = @input1
WHERE input2 = @input2
AND input3 NOT IN (123)
请问UPDATE总是只影响的具体哪一行?你是什么意思的输出?整排? – gbn