Results 1 to 2 of 2

Thread: [RESOLVED] Updating database using datagridview

  1. #1

    Thread Starter
    PowerPoster Radjesh Klauke's Avatar
    Join Date
    Dec 2005
    Location
    Sexbierum (Netherlands)
    Posts
    2,244

    Resolved [RESOLVED] Updating database using datagridview

    Ola,

    I'm loading a table from my database into a datagridview. Removing (multiple) rows from the database and the datagridview works great. Now I need to be able to add records directly into the database as soon as I add a new value into the datagrid.



    - the id is the same ID as in the database
    - the id-column is read-only
    - the "datum"-column is where I want to add a new date (as soon as I leave the column it should add it into the database and the id should be added, without reloading the database)

    Someone with some suggestions? Adding the id (without reloading the database) is actually the most important part, but I don't have a clue how to achieve this.

    Thanks in advance.


    If you found my post helpful, please rate it.

    Codebank Submission: FireFox Browser (Gecko) in VB.NET, Load files, (sub)folders treeview with Windows icons

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,684

    Re: Updating database using datagridview

    If you are adding rows to the last row in the DataGridView where the DataSource of the DataGridView is a DataTable you could setup a RowChanged event for the DataTable i.e.

    Code:
    AddHandler dt.RowChanged, AddressOf MyTable_RowChanged
    Then access the fields i.e.
    Code:
    Private Sub MyTable_RowChanged( _ 
        ByVal sender As Object, _ 
    	ByVal e As System.Data.DataRowChangeEventArgs) Handles MyTable.RowChanged
    
        If e.Action = DataRowAction.Add Then
    	    e.Row
        End If
    
    End Sub
    From there save data access via e.Row to your database, get the ID and assign the ID to the new row.

    If using MS-Access look at jmc's code bank submission for getting the new ID from an MS-Access table.

    Any ways these are parts that should assist if adding rows via the DataGridView last row.

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