parameterized update query does not update into db

jalo

Active member
Joined
Aug 9, 2005
Messages
28
Hi,

i am trying to parameterize my query, but for some reason it seems things go smoothly at runtime (i get no exceptions), but then there is no update in my Access database. i must be missing something - any ideas?

Here is my code:

Code:
Me.OleDbDataAdapter2 = New OleDb.OleDbDataAdapter("select * from Nuclear_Extension", Me.OleDbConnection1)

updateCommand2 = New OleDb.OleDbCommand("INSERT INTO Nuclear_Extension (SS_Event_Nuclear_ID, NYHA, MDReferring) VALUES (?, ?, ?)", Me.OleDbConnection1)

add parameters
updateCommand2.Parameters.Add(New OleDb.OleDbParameter("SS_Event_Nuclear_ID", OleDb.OleDbType.Integer))
updateCommand2.Parameters.Add(New OleDb.OleDbParameter("NYHA", OleDb.OleDbType.Integer))
updateCommand2.Parameters.Add(New OleDb.OleDbParameter("MDReferring", OleDb.OleDbType.VarChar, 30))
updateCommand2.Prepare()

Me.OleDbDataAdapter2.InsertCommand = updateCommand2
Me.OleDbDataAdapter2.MissingSchemaAction = MissingSchemaAction.AddWithKey

Me.OleDbDataAdapter2.Fill(Me.DataSet1, Me.NuclExtension)
 
updateCommand2.Parameters.Item("NYHA").Value() = Integer.Parse(Me.NYHA.Text)
updateCommand2.Parameters.Item("MDReferring").Value() = Me.RefMD.Text
updateCommand2.Parameters.Item("SS_Event_Nuclear_ID").Value() = Me.EventNuclID

update the database
            Me.OleDbDataAdapter2.Update(Me.DataSet1, Me.NuclExtension)
 
You should either use the DataAdapter with a DataSet OR a parameterized Update.

If you just want to insert your data into the DB:
Code:
updateCommand2 = New OleDb.OleDbCommand("INSERT INTO Nuclear_Extension (SS_Event_Nuclear_ID, NYHA, MDReferring) VALUES (?, ?, ?)", Me.OleDbConnection1)

add parameters
updateCommand2.Parameters.Add("SS_Event_Nuclear_ID", OleDb.OleDbType.Integer).Value() = 
Me.EventNuclID
updateCommand2.Parameters.Add("NYHA", OleDb.OleDbType.Integer).Value() = Integer.Parse(Me.NYHA.Text)
updateCommand2.Parameters.Add("MDReferring", OleDb.OleDbType.VarChar, 30).Value() = Me.RefMD.Text
 
Try
  Me.OleDbConnection1.Open()
  updateCommand2.ExecuteNonQuery()
Catch
Finally
  Me.OleDbConnection1.Close()
End Try
 
Back
Top