How do I update the SQL data after modifying a DATAGRID?

I need the code that will send the changes to SQL from any row modified in my DATAGRID.
My grid filling code is :
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        myConnection = New SqlConnection("server=dumbo;uid=sa;pwd=sas;database=rfp01")
        Dim cmd As New System.Data.SqlClient.SqlCommand
            Dim da As New SqlDataAdapter("Select * from matvar", myConnection)
            da.Fill(ds, "matvar")
            DataGrid1.DataSource = ds.DefaultViewManager
        End Try
    End Sub
Now in another button "UPDATE" what do I put to make the changes permenant in SQL?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeff CertainCommented:
Generally, I use my own direct UPDATE statement. However, you can use the dataadapter Update method. Visual Studio has pretty good help on this. You'll likely need to use the CommandBuiolder object to build the update command.

Also.... you don't need to open the connection to use a datadapter -- the dataadapter handles opening and closing the connection. You'll quickly find that your approach leads to orphaned connections. You can get away with it in SQL (although it is, effectively, a memory leak) but if you're using Access, your database will be mysteriously locked.
yyuubum2Author Commented:
I think I was wondering how I know which rows in my grid have been changed so I can just update those rows.
I'm a little shakey in this arena so please be a touch more illustrative in your suggestions ok?
Jeff CertainCommented:
The datadapter handles that for you. It knows what rows have been updated, deleted, and added. Each row in the dataset has a rowstate that is used to maintain this info.

This link provides details:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.