• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 175
  • Last Modified:

DataGridView update, add and removed rows

hi there,
I'm new with this datagridview stuff but i'm trying to get this working.
I have set up a data grid view and i'm populating the data ok but the problem here is when i try to update delete and add rows any changes i do they are not comitt to the database. my question here is how do i enable this commans?

and also, is there a way to have a navigation pane already build in to place on my from?
Thanks,
jsctechy
0
jsctechy
Asked:
jsctechy
1 Solution
 
jsctechyAuthor Commented:
i just remenber to post the code i'm sorry =0

 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


        cn = New SqlClient.SqlConnection(My.Settings.cnnJSVSDB)
        ds = New DataSet
        dv = New DataView
        ad = New SqlClient.SqlDataAdapter("SELECT CUSIP, SYMBOL, ADD_DATE, END_DATE, DROP_DATE, END_DROP_DATE FROM ADDS", cn)
        Dim commandBuilder As New SqlClient.SqlCommandBuilder(ad)
        ad.Fill(ds, "Production")
        dv.Table = ds.Tables("Production")

        Me.dgvAdds.DataSource = dv

        AddHandler dgvAdds.RowsAdded, AddressOf Added
        AddHandler dgvAdds.RowsRemoved, AddressOf Removed

    End Sub

 Private Sub Removed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowsRemovedEventArgs) 'Handles dgvAdds.RowsAdded
        ' Update the database with the user's changes.
        Me.ad.Update(Me.ds)

    End Sub
    Private Sub Added(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowsAddedEventArgs) 'Handles dgvAdds.RowsAdded
        ' Update the database with the user's changes.
        Me.ad.Update(Me.ds)

    End Sub
0
 
SanclerCommented:
It sounds as though the additions/removals have not been committed from the datagridview to the datatable when you call the update.  I'm not sure about that, because I've never used these events in that way.  But you can try

   CType(BindingContext(dv), CurrencyManager).EndCurrentEdit

as the first line in each of your subs: or, if you do not want to change the declaration of dv so that it will be visible to code like that, you could try

   CType(BindingContext(dgvAdds.DataSource), CurrencyManager).EndCurrentEdit

instead.

Roger
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now