INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Stored Procedure Loop Incrementing Incorrectly

Stored Procedure Loop Incrementing Incorrectly

(OP)
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 --> c#

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

CODE --> 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' 

RE: Stored Procedure Loop Incrementing Incorrectly

You are excuting twice

cmd.ExecuteNonQuery()

and then

_SSCCID = (string)cmd.ExecuteScalar();

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close