Update w/out select.

Nate Bross

Well-known member
Joined
Apr 6, 2005
Messages
601
Location
Chicago, IL
I have this code, which works; however, I dont want to select all events before I update. Is there a better way to do a simple Insert?
Code:
            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()
 
I dont 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?
 
Back
Top