|
-
Oct 18th, 2007, 03:46 PM
#1
Thread Starter
New Member
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.
-
Oct 18th, 2007, 04:12 PM
#2
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)
-
Oct 18th, 2007, 04:25 PM
#3
Thread Starter
New Member
Re: Cannot update my database!!!!
Ok... You are my new hero. That did it.
-
Oct 18th, 2007, 05:15 PM
#4
Thread Starter
New Member
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?
-
Oct 18th, 2007, 07:14 PM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|