troubleshooting Question

Recieve Must declare the scalar variable "@TextS" trying to update in VB.NET

Avatar of jeremyj54
jeremyj54 asked on
Microsoft SQL ServerVisual Basic.NET
3 Comments1 Solution638 ViewsLast Modified:
I am recieving "Error while updating record Must declare the scalar variable @TextS" when running the following code.

 con = dbConnect()
            cmd.Connection = con
            If txtResource.Text = "ALL" Then
                cmd.CommandText = "UPDATE OPERATION_BINARY SET BITS = CAST(REPLACE(BIT, @TextS, @TextR) as VARBINARY(MAX)) where CAST(CAST(OPERATION_BINARY.BITS AS VARBINARY(MAX)) AS VARCHAR(8000)) LIKE '%' + @Text + '%'"

                MsgBox(cmd.CommandText)
            Else
                cmd.CommandText = "UPDATE OPERATION_BINARY SET BITS = CAST(REPLACE(BITS, @TextS, @TextR) as VARBINARY) " & _
                "FROM OPERATION INNER JOIN " & _
                "OPERATION_BINARY ON OPERATION.WORKORDER_TYPE = OPERATION_BINARY.WORKORDER_TYPE AND " & _
                "OPERATION.WORKORDER_BASE_ID = OPERATION_BINARY.WORKORDER_BASE_ID And " & _
                "OPERATION.WORKORDER_LOT_ID = OPERATION_BINARY.WORKORDER_LOT_ID And " & _
                "OPERATION.WORKORDER_SPLIT_ID = OPERATION_BINARY.WORKORDER_SPLIT_ID And" & _
                "OPERATION.WORKORDER_SUB_ID = OPERATION_BINARY.WORKORDER_SUB_ID And OPERATION.SEQUENCE_NO = OPERATION_BINARY.SEQUENCE_NO " & _
                "WHERE (OPERATION.RESOURCE_ID = @Resource)"
            End If
            cmd.ExecuteNonQuery()
            cmd.Parameters.AddWithValue("@Resource", txtResource.Text)
            cmd.Parameters.AddWithValue("@TextS", Trim(txtSearch.Text))
            cmd.Parameters.AddWithValue("@TextR", Trim(txtReplace.Text))
ASKER CERTIFIED SOLUTION
DBAduck - Ben Miller
SQL Server Architect

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros