Results 1 to 5 of 5

Thread: Datagridview - saving data

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2010
    Posts
    285

    Unhappy Datagridview - saving data

    Good morning to everyone.

    In VB.net 2008 I would like to have a datagridview in a form.

    This datagridview, show the data of one MDB table.

    I pretend the user can change data, and save them.

    BUT, I DON'T want use the default save button created by the VB in the header of the form.

    Cause I have extra code to do in saving moment, I need to create my "save" button.

    What code should I enter in the click event of the button???

    I've tried many solutions, but none of them works..

    Thank You

  2. #2
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    595

    Re: Datagridview - saving data

    Code:
     Using con As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;Data Source=db1.mdb")
                con.Open()
                cmd = New OleDbCommand("Select * from Table1", con)
                Dim da As New OleDbDataAdapter(cmd)
                Dim dt As New DataTable
                da.Fill(dt)
                DataGridView1.DataSource = dt
            End Using

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2010
    Posts
    285

    Question Re: Datagridview - saving data

    Tommy,

    It wasn't that I needd.

    In another forum, answer me and work with:

    Me.Validate()
    Me.MovBindingSource.EndEdit()
    Me.TableAdapterManager.UpdateAll(Me.ApDataSet)


    But now, I have another big problem.

    How can I alter a global var, is any valu eof datagridview is changed?

    No one of the events works

  4. #4
    Hyperactive Member
    Join Date
    Dec 2007
    Location
    Somewhere else today
    Posts
    355

    Re: Datagridview - saving data

    It all depends on how the databinding to the datagridview has been setup. If you have bound the datatable directly to the dgv and setup the Insert, Delete & Update sql statements in the dataset designer (note : datatable must have an Index) then the code would be :

    Code:
    Me.Validate
    Me.datatableBindingSource.EndEdit()
    Me.datatableTableAdapter.Update(datatable)
    So no matter what you do in the dgv the data will be updated. This is the easiest way to handle data in the dgv.

    Computerman
    It was much easier in VB6, but I am now liking Vb.Net alot more.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2010
    Posts
    285

    Resolved Re: Datagridview - saving data

    Ir works perfectly

    Thank You

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