updating a field does not work

jalo

Active member
Joined
Aug 9, 2005
Messages
28
after reading some posts here, i even added the [] around the fields... but still the update does not update... pls help...

Code:
updateCommand3 = New OleDb.OleDbCommand("UPDATE [Event_Nuclear] SET [Event_Nuclear].[Number_Of_Levels] = ? WHERE [Event_Nuclear].[SS_Event_Nuclear_ID] = ?", Me.connection)

updateCommand3.Parameters.Add(New OleDb.OleDbParameter(Me.EventNuclID, OleDb.OleDbType.Integer))
updateCommand3.Parameters.Add(New OleDb.OleDbParameter("Number_Of_Levels", OleDb.OleDbType.Integer))
updateCommand3.Prepare()

updateCommand3.Parameters.Item("Number_Of_Levels").Value() = Integer.Parse(Me.TextBox1.Text)
            updateCommand3.Parameters.Item(Me.EventNuclID).Value() = Me.eventID

updateCommand3.ExecuteNonQuery()
 
if i replaced the first ? with an integer - it works...
but i still cant figure out what is wrong with the ? version.. if i print the value of the parameter after retrieving it from the textbox - it is the right value....
 
Last edited by a moderator:
oh... i figured it... i guess i cannot use ? (i.e. a parameter) in the SET section of the query. so i re-wrote like below and it works now! :p

Code:
[COLOR=Red]Dim temp As Integer = Integer.Parse(Me.TextBox1.Text)[/COLOR]

updateCommand3 = New OleDb.OleDbCommand("UPDATE [Event_Nuclear] SET [COLOR=Red][Event_Nuclear].[Number_Of_Levels] = " & temp & "[/COLOR] WHERE [Event_Nuclear].[SS_Event_Nuclear_ID] = ?", Me.connection)

updateCommand3.Parameters.Add(New OleDb.OleDbParameter(Me.EventNuclID, OleDb.OleDbType.Integer))
updateCommand3.Prepare()
 
You should be able to use a parameter to do this - I personally would always advise against using string concatenation to do DB stuff.
If you swap the order you add the parameters in does that work? Also is there a reason you are using Me.EventNuclID as the name of the parameter in your code?
 
Back
Top