Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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()

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

Posted

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?

Amir Syafrudin

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...