我沒有看到任何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