Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stored Procedure Loop Incrementing Incorrectly

Status
Not open for further replies.

RJL1

Technical User
Oct 3, 2002
228
US
Hello everyone.

I have a piece of code that I am working on to print some container labels. The application allows the user to put in the quantity they want to print and the code loops that many times executing the stored procedure which returns a container ID with check digit already calculated. My problem is when I run the stored procedure from SQL it increments my field by 1 as expected however when I run the application it returns 1,3,5,7 .... Almost as if it was firing the stored procedure twice but only getting the second container back from it.

If anyone could offer any suggestions or assistance helping me figure out what I have done wrong or a better way it would be greatly appreciated

Thanks
RJL

Here is my code
Code:
namespace MOD10
{
    public partial class Form1 : Form
    {
        // **********************************************************************************               
        // Connection Strings
        // **********************************************************************************

        // **********************************************************************************               
        // VARIABLES
        // **********************************************************************************

        string _Warehouse = "002";
        string _Company = "001";
        string _FromLoc = "RECV-01";
        string _ToLoc = "001-001";
        string _Item = "00004";
        string _ItemDesc = "test item for receiving lpn";
        string _Quantity = "5";
        string _QtyUM = "CS";
        string _ExpDate = "1/1/2015";
        string _Lot = "WP20150101";
        string _User = "rluna";

        string _FilePath = "";
        string _Printer = "Local Zebra 105SL";

        string _SSCCID = "";
        string _SSCC = "";

        //-----------------------------------------------------------------

        int _Qty = 0;
        int _PalletNum = 1;

        //-----------------------------------------------------------------
        
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
              
        }

        private void button1_Click(object sender, EventArgs e)
        {
            LoopCounter();
        }

        //-----------------------------------------------------------------
        //-----------------------------------------------------------------

        private void LoopCounter()
        {
            _Qty = Convert.ToInt32(txtLPNQty.Text);

            int _Count = 0;

            while (_Count < _Qty)
            {
                GetSSCCID();
                _Count = _Count + 1;
            }
        }

        // **********************************************************************************               
        // ZPL code to create .lbl file to send to the printer
        // **********************************************************************************

        private void GetSSCCID()
        {
            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "SP_CALCULATE_SSCC_ID";
            cmd.CommandType = CommandType.StoredProcedure;

            cs.Open();
            cmd.Connection = cs;
            cmd.ExecuteNonQuery();

            _SSCCID = (string)cmd.ExecuteScalar();

            cs.Close();

            LabelCode();
         }

        private void LabelCode()
        {
            _SSCC = "(00)3" + _SSCCID;

            listBox1.Items.Add(_SSCC);
         
            PrintLabel();
        }
    }
}

Also the Stored Procedure is that helps

SQL:
DECLARE	@CUSTOMER_ID VARCHAR(7)
DECLARE	@WEPACK_ID VARCHAR(3)
DECLARE	@LPN_ID VARCHAR(6)
DECLARE	@SSCC VARCHAR(17)

SET @CUSTOMER_ID = 
(SELECT D.USER1VALUE FROM GENERIC_CONFIG_DETAIL D 
 WHERE D.RECORD_TYPE = 'Company LPN Settings' AND D.IDENTIFIER = 'CompanyName')

SET @WEPACK_ID = 
(SELECT D.USER5VALUE FROM GENERIC_CONFIG_DETAIL D 
 WHERE D.RECORD_TYPE = 'Company LPN Settings' AND D.IDENTIFIER = 'CompanyName')
 
SET @LPN_ID =
(SELECT D.USER4VALUE FROM GENERIC_CONFIG_DETAIL D 
 WHERE D.RECORD_TYPE = 'Company LPN Settings' AND D.IDENTIFIER = 'CompanyName')

SET @SSCC = @CUSTOMER_ID + @WEPACK_ID + @LPN_ID

------------------------------------------------------------
SELECT [dbo].[fnGetSSCC](@SSCC) AS 'SSCCID'
------------------------------------------------------------

DECLARE	@NEXT_NUM VARCHAR(6)

SET @NEXT_NUM =
(SELECT D.USER4VALUE FROM GENERIC_CONFIG_DETAIL D 
 WHERE D.RECORD_TYPE = 'Company LPN Settings' AND D.IDENTIFIER = 'CompanyName')

UPDATE GENERIC_CONFIG_DETAIL SET
GENERIC_CONFIG_DETAIL.USER4VALUE = CAST(@NEXT_NUM AS int) + 1
WHERE
GENERIC_CONFIG_DETAIL.RECORD_TYPE = 'Company LPN Settings' 
AND GENERIC_CONFIG_DETAIL.IDENTIFIER = 'CompanyName'
 
You are excuting twice

cmd.ExecuteNonQuery()

and then

_SSCCID = (string)cmd.ExecuteScalar();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top