We help IT Professionals succeed at work.
Get Started

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

636 Views
Last Modified: 2012-04-14
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))
Comment
Watch Question
SQL Server Architect
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE