title: Sqlcommand Parameters not executing
body: <p>I am encountering a strange problem when attempting to execute a DELETE query agains a SQL Server table using VB.NET, SQL Command, and Parameters.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>Try    
      sqlCommand.Transaction = transaction1
      sqlCommand.Connection = conn
      sqlCommand.CommandText = sqlQuery
      sqlCommand.Parameters.Add("@userID", SqlDbType.Int).Value = Convert.ToInt32(userID)
      sqlCommand.Parameters.Add("@groupID", SqlDbType.Int).Value = Convert.ToInt32(groupID)
      ''#Delete the user from the group.
      MessageBox.Show("User: " + Convert.ToString(userID) + "    Group: " + Convert.ToString(groupID))
      MessageBox.Show("Param, UserID: " + sqlCommand.Parameters.Item(0).Value.ToString)
      MessageBox.Show("Param, GroupID: " + sqlCommand.Parameters.Item(1).Value.ToString)
      return_deleteUser = sqlCommand.ExecuteNonQuery()
  Catch ex As Exception
      transaction1.Rollback()
      Dim hr As Integer = Marshal.GetHRForException(ex)
      MsgBox("Removal of user from group has failed: " + ex.Message() &amp; hr)
  End Try
  </code></pre>
  
  <p>Which executes the following SQL Query:</p>
  
  <pre><code>Dim sqlQuery As String = "DELETE FROM MHGROUP.GROUPMEMS WHERE USERNUM =@userID AND GROUPNUM =@groupID"
  </code></pre>
  
  <p>My problem is that when the code executes, there is no error reported at all.  I have ran SQL Profiler and the query doesn't appear in the trace list.  The three messageboxes that I have added all return the correct values, and if I was to execute the SQL query against the table with the values the query succeeds.  Both the userID and groupID are 3-digit integers.</p>
  
  <p>Can anyone suggest why the code is not working as intended, or any further debugging that I can use to step through the code?  Ideally I would love to see the completed SQL query with the parameters completed, but I haven't found out how to do this.</p>
  
  <p><strong>EDIT:</strong>
  I have the following later in the code to check if the execute's all processed successfully:</p>
  
  <pre><code>If return_insertEvent &gt; 0 And return_updateUser &gt; 0 And return_nextSID &gt; 0 And return_deleteUser &gt; 0 Then
      MessageBox.Show("Success")
      return_removeADGroup = RemoveUserFromGroup(userID, groupName)
      MessageBox.Show("Remove FS User from AD Group: " + return_removeADGroup)
      transaction1.Commit()
      transaction2.Commit()
      transaction3.Commit()
      transaction4.Commit()
      returnResult = 1
  Else
      transaction1.Rollback()
      transaction2.Rollback()
      transaction3.Rollback()
      transaction4.Rollback()
      returnResult = 0
  End If
  </code></pre>
  
  <p>If you require any further information please don't hesitate in contacting me.</p>