jalo Posted August 21, 2005 Posted August 21, 2005 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) Quote
FZelle Posted August 22, 2005 Posted August 22, 2005 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 Quote
jalo Posted August 22, 2005 Author Posted August 22, 2005 i see - makes sense and it works! :-) thanks! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.