Note that there are some explanatory texts on larger screens.

plurals
  1. POC# program linked to SQL Server not running update query unless in debug mode
    primarykey
    data
    text
    <p>I have a program that interfaces with SQL server written in C#. I'm using stored procedures with parameterization. </p> <p>I have an action that changes a flag and then loops through a listbox, changing a flag in the database for each item. When I run the program it changes the flag but not the flags for the listbox; but when I run it through in debug mode it does.</p> <p>C# code:</p> <pre><code>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 &lt; 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(); } </code></pre> <p>Procedure that isn't running:</p> <pre><code>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 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload