Results 1 to 11 of 11

Thread: Datagridview Addition/deletion/modification

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2011
    Location
    Oregon City, Oregon
    Posts
    705

    Datagridview Addition/deletion/modification

    Some weeks ago, I posted a question and instead of help received a rather toxic scree (that is the word I want to use and is appropriate to the action) from a alleged authority, instead of any help or useful suggestions.

    I spent quite a bit of time on this and eventually figured out what was required. It was nothing complex, or particularly tricky, and could have been addressed by anyone who has any knowledgeable advice. I was able to finally resolve the issue myself.

    The original issue was that I had a DGV bound to a table and I wanted to add/delete and modify records in the dgv and have those changes reflected in the table (ACCESS). I had looked at numerous methods and found two that were promising.

    The first was a commonly used method based on a routine requiring that the whole dgv be processed in a loop containing a query, and using
    Code:
    Command.ExecuteNonQuery()
    . I was able to make this method work, but not well.

    The second method was based on the adapter.Update command and, at the time, I was completely unable to make this method work at all.


    Name:  DGV.jpg
Views: 782
Size:  18.5 KB


    What was required was to set the correct properties and use the code below.

    Code:
        Private Sub fileScan_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown
            LoadGrid()
            SetState()
        End Sub
    Code:
        Private Sub LoadGrid()
            SetQuery()
            If RecordCount > 0 Then
                dgvList.DataSource = FileMaster.ListDataSet.Tables(0)
                dgvList.Rows(0).Selected = True
    
    
                FileMaster.ListAdapter.UpdateCommand = New OleDbCommandBuilder(FileMaster.ListAdapter).GetUpdateCommand
            End If
        End Sub
    Code:
        Private Sub SetQuery()
    #Region "Establish Connection and execute query"
            FileMaster.ScanMasterQuery("SELECT colScan,colScanPath FROM lkpScan")
    #End Region
        End Sub
    The key to the whole process is the line:

    Code:
    FileMaster.ListAdapter.UpdateCommand = New OleDbCommandBuilder(FileMaster.ListAdapter).GetUpdateCommand
    found in LoadGrid().

    In my previous post my intelligence was questioned for even using this line. It turns out that one can do just about anything wanted to a dgv using this method.

    At the end of the day, it is really good that there is someone that is willing to assist those of us who might not be experts. Most of the experts here do indeed provide that wonderful service. However, there are some alleged experts who often have nothing to offer but to question my intelligence for even asking a question, and then offer NO useful information, or gibberish instead of useful information.
    Last edited by gwboolean; Jun 10th, 2022 at 11:49 AM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width