Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6951231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:11:35+00:00 2026-05-27T14:11:35+00:00

This is so simple, I must be stupid! I have a simple access database

  • 0

This is so simple, I must be stupid!

I have a simple access database that a log record gets written to a few times an hour.

I’m trying to make a DataGridView that shows that data as it arrives.

My “Solution” is simple;

when a user clicks the view -> read from the database (fill the datatable) -> update the view.

Not what I dreamed of, but functional, if totally sub-optimal.

However, my “solution” is a dud, using fill draws every single record from the database, even if there are already 599 on screen.

Really, I just want fill the datatable once, and add new records as they arrive (or on click if needs be).

Bonus point if you can also explain another way (that isn’t called so often) to hide the ID column, and change the header of column 1 (named DateTimeStamp) to TimeStamp.

Public Class FormMain

    Shared dataAdapter As OleDbDataAdapter
    Shared logTable As New DataTable("log")
    Shared commandBuilder As OleDbCommandBuilder
    Shared queryString As String = "SELECT * FROM log"
    Shared bindingSource As New BindingSource

    Private Sub FormServerBridge_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            ConfigureDataSet()
            ConfigureBindingSource()
            ConfigureDataView()
        Catch ex As Exception
            ' FIXME: Helpful for debugging purposes but awful for the end-user.
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub ConfigureDataSet()
        dataAdapter = New OleDbDataAdapter(queryString, _Config.ConnectionString)
        commandBuilder = New OleDbCommandBuilder(dataAdapter)
        commandBuilder.GetUpdateCommand()

        dataAdapter.Fill(logTable)

        With logTable
            .Locale = System.Globalization.CultureInfo.InvariantCulture
            .PrimaryKey = New DataColumn() {logTable.Columns("ID")}
        End With
    End Sub

    Private Sub ConfigureBindingSource()
        With bindingSource
            .DataSource = logTable
        End With
    End Sub

    Private Sub ConfigureDataView()
        With DataGridView
            .DataSource = bindingSource
        End With
    End Sub

    Private Sub DataGridView_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView.Click
        UpdateUI()
    End Sub

    Sub UpdateUI()
        dataAdapter.Fill(logTable)
    End Sub

    Private Sub DataGridView_DataBindingComplete(ByVal sender As Object, ByVal e As DataGridViewBindingCompleteEventArgs) Handles DataGridView.DataBindingComplete

        ' FIXME: This code gets run as many times as there are rows after dataAdapter.Fill!

        With DataGridView
            .Columns("ID").Visible = False

            .Columns(1).HeaderText = "Timestamp"

            .Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
            .Columns(2).AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells
            .Columns(3).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
        End With

    End Sub
End Class

p.s. Links to websites and books will be appreciated, even the right MSDN page (if you know where it is, I admit I find it uncomfortable to peruse, I regularly get lost).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T14:11:36+00:00Added an answer on May 27, 2026 at 2:11 pm

    Assuming your IDs are sequential, the way I would approach this is:

    1) Record the last id that you retrieved

    2) When the user presses view, only get records whose IDs are greater than the last one record

    3) Retrieve the records into a new datatable and then merge that with your existing data set.

    Here is how I would make the changes (only changed info included):

    Public Class FormMain
    
        Shared logTable As DataTable
        Shared bindingSource As New BindingSource
    
        Private m_wLastID As Integer
    
        Private Sub FormServerBridge_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Try
                ConfigureDataSet()
                ConfigureBindingSource()
                ConfigureDataView()
            Catch ex As Exception
                ' FIXME: Helpful for debugging purposes but awful for the end-user.
                MessageBox.Show(ex.Message)
            End Try
        End Sub
    
        Private Sub ConfigureDataSet()
    
            Dim queryString As String
    
            queryString = "SELECT * FROM log WHERE ID > " & m_wLastID.ToString & " ORDER BY ID"
    
            Using dataAdapter As New OleDbDataAdapter(queryString, _Config.ConnectionString)
                Using commandBuilder As New OleDbCommandBuilder(dataAdapter)
                    Dim oDataTable As New DataTable("log")
    
                    commandBuilder.GetUpdateCommand()
    
                    dataAdapter.Fill(oDataTable)
    
                    With oDataTable
                        .Locale = System.Globalization.CultureInfo.InvariantCulture
                        .PrimaryKey = New DataColumn() {.Columns("ID")}
                    End With
    
                    ' Record the last id
                    If oDataTable.Rows.Count <> 0 Then
                        m_wLastID = CInt(oDataTable.Rows(oDataTable.Rows.Count - 1)("ID"))
                    End If
    
                    If logTable Is Nothing Then
                        logTable = oDataTable
                    Else
                        logTable.Merge(oDataTable, True)
                        logTable.AcceptChanges()
                    End If
                End Using
            End Using
        End Sub
    
        Sub UpdateUI()
            ConfigureDataSet()
        End Sub
    
        ' Rest of the form code here
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this idea that using SQL VIEWS to abstract simple database computations (such
I think this must be simple but I can't get it right... I have
This probably has a simple answer, but I must not have had enough coffee
I'm must be doing something stupid, because I can't make this simple animate work
It's late, so this must be something stupid. I have LinqPad connected up to
This must be something utterly stupid that I've done or am doing, but I
Been struggling with this simple selector problem a couple of hours now and must
This must be simple, but I can't seem to figure it out. I am
I must be going insane. This is incredibly simple so I am apparently overlooking
This must be a very simple question, but I don't seem to be able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.