Results 1 to 5 of 5

Thread: Cannot update my database!!!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    6

    Cannot update my database!!!!

    I am having a real hard time updating my database with an updated order status changed in a combobox.

    I have a sub that calls my update Function based on my combobox text changing. It sends the OrderID (This is the primary key) to the function as intOrderID. My function is below. However I cannot get it to work I keep getting an error:

    Private Function UpdateOrderStatus(ByVal intOrderID)
    Dim con As New SqlConnection
    Dim cmd As SqlCommand = New SqlCommand
    Dim intRowsAffected As Integer


    con.ConnectionString = My.Settings.TechTrackerConnectionString

    cmd.CommandType = CommandType.Text
    cmd.CommandText = "UPDATE OrderDetails SET Status = @Status WHERE OrderID = @OrderID"
    cmd.Connection = con

    cmd.Parameters.Add("@Status", SqlDbType.VarChar, 25, cboMonitorSelectedStatus.Text)
    cmd.Parameters.Add("@OrderID", SqlDbType.Int, 4, intOrderID)

    con.Open()

    intRowsAffected = cmd.ExecuteNonQuery()
    MessageBox.Show(intRowsAffected)

    con.Close()


    End Function

    The error I get is this:

    The parameterized query '(@Status varchar(25),@OrderID int)UPDATE OrderDetails SET Status' expects the parameter '@Status', which was not supplied.

    PLEASE help me with this. I have searched everywhere for an answer and spent about week trying to figure this out.

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Cannot update my database!!!!

    Change these two lines
    Code:
    cmd.Parameters.Add("@Status", SqlDbType.VarChar, 25, cboMonitorSelectedStatus.Text)
    cmd.Parameters.Add("@OrderID", SqlDbType.Int, 4, intOrderID)
    To this
    Code:
    cmd.Parameters.AddWithValue("@Status", cboMonitorSelectedStatus.Text)
    cmd.Parameters.AddWithValue("@OrderID", intOrderID)

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    6

    Re: Cannot update my database!!!!

    Ok... You are my new hero. That did it.

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2007
    Posts
    6

    Re: Cannot update my database!!!!

    Ok I may have lied. It seems as though it worked, The listview is populated with the change. The details all seem to be right as long as the application is running. However if I close the application and look at the database, or even just open the application again, the original entry is still in there. The changes are never written to the database.

    Any ideas?

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: Cannot update my database!!!!

    That is entirely a different problem. Check out this thread and read post # 2 by JMC:
    http://www.vbforums.com/showthread.p...ase+copy+newer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width