Code to instantiate the Access database and table...
Expand|Select|Wrap|Line Numbers
- Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & db.Name)
- conn.Open()
- Dim oda As New OleDb.OleDbDataAdapter("select " & sqlCols & " from [" & txtOutputTable.Text.Trim & "];", conn)
- Dim cb As New OleDb.OleDbCommandBuilder(oda)
- cb.QuotePrefix = "["
- cb.QuoteSuffix = "]"
- oda.UpdateCommand = cb.GetUpdateCommand
- oda.InsertCommand = cb.GetInsertCommand
- oda.DeleteCommand = cb.GetDeleteCommand
- Dim ds As New DataSet
- oda.Fill(ds, txtOutputTable.Text.Trim)
The program then goes off to another source and builds a data array based upon time range and data items. Date and hour are the first two columns and the remaining data fleshes out the rest of the columns. This data may need to update the table contents or be inserted. The data array def is as follows:
Expand|Select|Wrap|Line Numbers
- Dim da(iHrs, iCols) As Object
Expand|Select|Wrap|Line Numbers
- For i = 0 To da.GetUpperBound(0)
- ds.Tables(0).BeginLoadData()
- Dim dr(da.GetUpperBound(1) + 1) As Object
- dr(0) = CDate(da(i, 0).ToString.Substring(0, 11))
- dr(1) = da(i, 0).ToString.Substring(12, 2)
- For j = 1 To da.GetUpperBound(1)
- dr(j + 1) = da(i, j)
- Next
- ds.Tables(0).LoadDataRow(dr, False)
- ds.Tables(0).EndLoadData()
- Next
Expand|Select|Wrap|Line Numbers
- Try
- oda.Update(ds, txtOutputTable.Text.Trim)
- Catch ex As Exception
- MsgBox(ex.Message)
- End Try