1

我有一个与用 C# 编写的 SQL 服务器交互的程序。我正在使用带有参数化的存储过程。

我有一个更改标志的操作,然后循环遍历列表框,为每个项目更改数据库中的标志。当我运行程序时,它会更改标志,但不会更改列表框的标志;但是当我在调试模式下运行它时它确实如此。

C#代码:

DialogResult results = MessageBox.Show("Warning: This action is irreversable." + System.Environment.NewLine + "Are you sure you want to make " /*MPI Number and Rev*/ + " active?", "Confirm MPI Rev Status Change", MessageBoxButtons.YesNo);
            if (results == DialogResult.Yes)
            {
                //Set previous CID
                SqlConnection PreviousCIDConnection = new SqlConnection();
                SqlCommand PreviousCIDCommand = new SqlCommand("dbo.ViewMPI_PreviousCIDActive", PreviousCIDConnection);
                PreviousCIDCommand.Parameters.AddWithValue("@MPINumber", MPINumber);
                DataSet PreviousCIDDataset = ViewMPIScreen.GetValues(PreviousCIDCommand);
                PreviousCID = System.Convert.ToInt32(PreviousCIDDataset.Tables[0].Rows[0][0].ToString());

                //Mark the selected copy locations as destroyed
                for (int i = 0; i < LocationsCheckedListBoxActivate.Items.Count; i++)
                {
                    if (LocationsCheckedListBoxActivate.GetItemChecked(i))
                    {
                        SqlConnection DeleteLocConnection = new SqlConnection();
                        SqlCommand DeleteLocCommand = new SqlCommand("dbo.UndestroyedCopies_Destroy", DeleteLocConnection);
                        DeleteLocCommand.Parameters.AddWithValue("@RCID", System.Convert.ToInt32(ActivateLocDatatable.Rows[i][8].ToString()));
                        DeleteLocCommand.Parameters.AddWithValue("@EngID", EngID);
                        DeleteLocCommand.Parameters.AddWithValue("@IssueDestroyDate", DateTime.Now.ToString());
                        ViewMPIScreen.ChangeValues(DeleteLocCommand);//Calls the method in ViewMPIScreen.cs that deletes, updates, or inserts data into the database
                    }
                }
                //Make the old revision inactive and the new revision active
                SqlConnection ActivateConnection = new SqlConnection();
                SqlCommand ActivateCommand = new SqlCommand("dbo.ActivateMPI_Activate", ActivateConnection);
                ActivateCommand.Parameters.AddWithValue("@PreviousCID", PreviousCID);
                ActivateCommand.Parameters.AddWithValue("@CID", CurrentCID);
                ViewMPIScreen.ChangeValues(ActivateCommand);

                this.DialogResult = DialogResult.OK;
                this.Close();
            }

未运行的程序:

CREATE PROCEDURE [dbo].[UndestroyedCopies_Destroy]
    @RCID               INT,
    @EngID              SMALLINT,
    @IssueDestroyDate   SMALLDATETIME
AS
BEGIN
    SET NOCOUNT ON
    --Who destroyed the copy and issued the new copy
    UPDATE
        dbo.tbl51RevCopies
    SET
        EngID = EngID
    WHERE
        RCID = @RCID;
    --When the copy was issues and the previous destroyed
    UPDATE
        dbo.tbl51RevCopies
    SET
        IssueDestroyDate = @IssueDestroyDate
    WHERE
        RCID = @RCID;
    --Flag that says the copy was destroyed
    UPDATE
        dbo.tbl51RevCopies
    SET
        Destroyed = 1
    WHERE
        RCID = @RCID;
END
GO
4

0 回答 0