locked
Cannot Update More than once????? RRS feed

  • Question

  • User592532569 posted

    Whenever I try to update more than once I get an error COM object that has been separated from its underlying RCW cannot be used.

    My code is:

    objconn.Open()
            objcmd.Connection = objconn
            objcmd.CommandText = "UPDATE Kitchen SET SerialNo=mSerialNo, CustomerName = mCustomerName, ContainerNo = mContainerNo WHERE ABNo = mABNo"
            objcmd.Parameters.AddWithValue("mSerialNo", Val(TxtSer.Text))
            objcmd.Parameters.AddWithValue("mCustomerName", TxtBxCust.Text)
            objcmd.Parameters.AddWithValue("mContainerNo", Val(TxtBxContNo.Text))

     objcmd.Parameters.AddWithValue("mABNo", Val(TxtSearch.Text))


            objcmd.ExecuteNonQuery()// This line causes the error
            objconn.Close()

    Sunday, April 8, 2012 1:46 PM

Answers

  • User-417784260 posted

    I think you are reusing the connection.  I would not recommend reusing the connection on a web page.  You should create one when you need it, open, use, close, dispose of it.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 8, 2012 1:53 PM
  • User-1199946673 posted

    OleDbCommand will automatically find parameters' names accroding to the specific symbol "@"……

    No, OleDb will interpret any identifier it doesn't recognize as a valid table-, query-, field- or function-name as a parameter. Parameters do not need to start with an @, although it is good practice to use them anyway....

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 10, 2012 3:00 AM

All replies

  • User-417784260 posted

    I think you are reusing the connection.  I would not recommend reusing the connection on a web page.  You should create one when you need it, open, use, close, dispose of it.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, April 8, 2012 1:53 PM
  • User3866881 posted

    Hello purnesh:)

    【Solutions】

    Please change your commandText to this(by adding "@" as a prefix to declar all kinds of parameters……)

    objcmd.CommandText = "UPDATE Kitchen SET SerialNo=@mSerialNo, CustomerName = @mCustomerName, ContainerNo = @mContainerNo WHERE ABNo = @mABNo"

    【Reasons】

    OleDbCommand will automatically find parameters' names accroding to the specific symbol "@"……If you miss it,it's a general command instead of that with parameters。So your error will be thrown out。

    Reguards!

    Monday, April 9, 2012 9:28 PM
  • User-1199946673 posted

    OleDbCommand will automatically find parameters' names accroding to the specific symbol "@"……

    No, OleDb will interpret any identifier it doesn't recognize as a valid table-, query-, field- or function-name as a parameter. Parameters do not need to start with an @, although it is good practice to use them anyway....

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 10, 2012 3:00 AM
  • User3866881 posted

    Hello hans_v:)

    Haven't seen you for good……Hummmm……Yes, it's a good habit,I just want to tell the customer the good habit……

    Well……another way is you can use ?(question mark)……What do you think of this?

    Reguards!

    Tuesday, April 10, 2012 3:22 AM