Inserting Data To Sql Database Follow

0
Avatar
Legacy Poster

Hello,

I am new to BarTender and have had some success with this, but still have some issues.

I would appreciate any help on this.

 

Here is what I am doing.  I have created a task in Commander to listen for two pieces of data and once the connection closes, it sends this data to BarTender.  The first piece of data is an order number and the second is the quantity.  They are separated by a comma.  I have set up in Bartender the two database fields (Field1 and Field2).

 

I am taking this order number and quantity using that as parameters in a stored procedure to insert a record into a SQL database.  This same stored procedure returns a unique number that will be printed on the label.  No other information is needed on the label but this unique number.

 

I have written the stored procedure, and know it works.  I have also written vbscript and put it in the barcode object under the OnNewRecord Event Control and that works too.

 

Here is the problem.  It seems that the vbscript is run multiple times even though I sent one record (order number and quantity).  I know this because in the db table, I see 13 added records.  One of those records is correct, but the other 12 have the "sample" data (12345678) as the order number.

 

I am not sure why this is happening.

Thanks for any help folks can offer.

Frank

 

Here is a copy of the vbscript.  NOTE: Server name and database name have been changed to protect the innocent.  :)

 

Dim cmd
Dim retval
Dim TheQty

Set objConnection = CreateObject("ADODB.Connection")
Set cmd = CreateObject("ADODB.Command")

objConnection.Open "Provider=SQLNCLI10;Server=MySQLServer;Database=MyDatabase;Trusted_Connection=yes;"

With cmd
    .CommandType = 4
    .ActiveConnection = objConnection
    .CommandText = "sp_InsertOrderRecord"
    .Parameters.Append .CreateParameter ("@OrderNb",200,1,10,Field("Pallet.Field 1"))
    .Parameters.Append .CreateParameter ("@Qty",3,1,4,Field("Pallet.Field 2") )
    .Parameters.Append .CreateParameter ("@UniqueNb",200,2,32)
    .Execute
    retval = cmd.parameters("@UniqueNb").value
End With
Set cmd = Nothing
Set objConnection = Nothing

Value = retval

 

 

2 comments

0
Avatar
Michael Toupin (mtoupin
Comment actions Permalink

What event is the VB script set to execute on?

0
Avatar
Legacy Poster
Comment actions Permalink

Hi Mike,

I am putting it in the OnNewRecord event. 

Also, I forgot to mention that I am on version 9.2

 

Thanks!

Please sign in to leave a comment.