Nate Bross Posted February 21, 2007 Posted February 21, 2007 I have this code, which works; however, I don't want to select all events before I update. Is there a better way to do a simple Insert? Dim drnew As System.Data.DataRow cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & dbPath & ";") cn.Open() sql = "select * from events" myDataAdapter = New OleDbDataAdapter (sql, cn) Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(myDataAdapter) myDataAdapter.Fill(dsEventTemplate) drnew = dsEventTemplate.Tables(0).NewRow() drnew.Item("LocID") = TextBox1.Text drnew.Item("EventDescription") = editEventDescription.Text drnew.Item("EventStartTime") = editStartTime.Text drnew.Item("EventEndTime") = editEndTime.Text drnew.Item("EventCreationDate") = Now dsEventTemplate.Tables(0).Rows.Add(drnew) builder.GetUpdateCommand() myDataAdapter.Update(dsEventTemplate) Catch ex As Exception MsgBox(ex.Message) End Try cn.Close() Quote ~Nate� ___________________________________________ Please use the [vb]/[cs] tags on posted code. Please post solutions you find somewhere else. Follow me on Twitter here.
amir100 Posted February 21, 2007 Posted February 21, 2007 I don't think you need to call the Fill method before your call to the Update method. A straight forward solution would be using an OleDbCommand object. But then you have to specify the Insert query manually. :D Btw, are you sure this is the right place to post your problem? Quote Amir Syafrudin
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.