troubleshooting Question

How to update DataGridView to DataSet / Table

Avatar of Netlink2
Netlink2 asked on
Visual Basic.NET
4 Comments2 Solutions1347 ViewsLast Modified:
Hi experts, I hope this is an easy question, I imagine it should be:

My Table isn't updating.

the following is my class and code.

Public Class frmBranches
    Dim DS As DataSet
    Dim MyConnection As SqlConnection
    Dim MyCommand As SqlDataAdapter
    Dim SqlStr As String
    Private Sub frmBranches_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        SqlStr = "select * from tblBranches"
        MyConnection = New SqlConnection("Data Source=SERVER;Initial Catalog=ALC;Integrated Security=True")
        MyCommand = New SqlDataAdapter(SqlStr, MyConnection)
        DS = New DataSet()
        MyCommand.Fill(DS, "Royalties")
        DataGridView1.DataSource = DS.Tables("Royalties").DefaultView
    End Sub

    Private Sub cmdClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClose.Click
        Me.Hide()
    End Sub


    Private Sub cmdUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdUpdate.Click

        DS.AcceptChanges()
        MyCommand.Update(DS, "Royalties")
        DS.AcceptChanges()

    End Sub

End Class
ASKER CERTIFIED SOLUTION
Manish Chhetia
Manager

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros