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