Stored-Procedures
儲存過程的參數太多
這是我的儲存過程的程式碼,有很多事情正在發生,還有很多參數正在傳遞。我知道 sql,我確信有更好的方法來執行這些功能,但需要一些幫助!提前致謝!:)
ALTER PROCEDURE [dbo].[spCompleteRepair] @unit_id INT, @BasicHB NVARCHAR, @AdvHB NVARCHAR, @CCRepair BIT, @CCReplace BIT, @Fan NVARCHAR, @RE BIT, @notes NVARCHAR, @bin_num NVARCHAR, @loc_num NVARCHAR, @repairserial NVARCHAR AS BEGIN INSERT INTO RepairDetails (unit_id, BasicHB, AdvHB, CCRepair, CCReplace, Fan, RE, notes, completion_date) VALUES (@unit_id, @BasicHB, @AdvHB, @CCRepair, @CCReplace, @Fan, @RE, @notes, GETDATE()) UPDATE Units SET bin_num=@bin_num, loc_num=@loc_num, repair_serial=@repairserial, unit_status=1 WHERE unit_id=@unit_id UPDATE OutBins SET filled=1 WHERE bin_num=@bin_num AND loc_num=@loc_num UPDATE Orders SET Orders.order_status = 1 FROM Orders --check to see if there are units for the order WHERE EXISTS ( SELECT * FROM Units WHERE Units.order_id = Orders.order_id ) --make sure there are NO units that are not status = 1 AND NOT EXISTS ( SELECT * FROM Units WHERE Units.order_id = Orders.order_id AND Units.unit_status <> 1) END CODE TO CALL PROCEDURE: using (SqlCommand command = new SqlCommand("spCompleteRepair", connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@order_id", txtorder_id.Text); command.Parameters.AddWithValue("@unit_id", txtunit_id.Text); command.Parameters.AddWithValue("@BasicHB", ddlBasicHB.Text); command.Parameters.AddWithValue("@AdvHB", ddlAdvHB.Text); command.Parameters.AddWithValue("@CCRepair", ddlCCRepair.Text); command.Parameters.AddWithValue("@CCReplace", ddlCCReplace.Text); command.Parameters.AddWithValue("@Fan", ddlFan.Text); command.Parameters.AddWithValue("@RE", ddlRE.Text); command.Parameters.AddWithValue("@notes", txtNotes.Text); command.Parameters.AddWithValue("@repairserial", txtRepairSerial.Text); command.Parameters.AddWithValue("@bin_num", ddl_binnum.Text); command.Parameters.AddWithValue("@loc_num", ddl_locnum.Text); command.Connection.Open(); command.ExecuteNonQuery(); }
您用來呼叫儲存過程的 C# 程式碼
@order_id
作為第一個參數傳入。實際儲存過程中未引用該參數。嘗試從 C# 程式碼中刪除該參數。