Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

 

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)

Posted

You should either use the DataAdapter with a DataSet OR a parameterized Update.

 

If you just want to insert your data into the DB:

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...