Save Datagrid Updates To SQL

Ok, I have spent about 2 whole days on this and I cannot get this to work. I have a table in a database with the following schema where ID is an identity column:
I have a datagrid in a WPF window that I fill doing this:

    Private conn As SqlConnection
    Dim dt As New DataTable("Employee")
    Private adapter As SqlDataAdapter
    Public Sub New()

        ' This call is required by the designer.

        Dim sda As SqlDataAdapter
        Dim CmdString As String = String.Empty
        Using con As New SqlConnection(sqlconnXML)
            CmdString = "SELECT ID, fullname, Title, Cell, Carrier From Contacts"
            Dim cmd As New SqlCommand(CmdString, con)
            adapter = New SqlDataAdapter(cmd)
            DataGrid1.ItemsSource = dt.DefaultView
            DataGrid1.DataContext = dt

        End Using
        ' Add any initialization after the InitializeComponent() call.
        DataGrid1.SelectedItem = Nothing
    End Sub

Open in new window

I have a button in said window that I would like to use to save any changes/additions/deletions to this datagrid back to my SQL database.  I am at this point now (after trying 100 other things) and this gives me an error "The ConnectionString property has not been initialized."

 Using con As New SqlConnection(sqlconnXML)
            Dim myBuilder As SqlCommandBuilder = New SqlCommandBuilder(adapter)


            adapter.UpdateCommand = myBuilder.GetUpdateCommand()

        End Using

Open in new window

How can I get this to work?  I did see some stuff here on EE about Entity Framework (TheLearnedOne suggested), however, it seemed like that may complicate things for me.  I'd like to keep this simple for both me and the deployment of this application.  Thanks for any help on this.
G ScottAsked:
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.

SAMIR BHOGAYTAFreelancer and IT ConsultantCommented:
you need to execute the command, not simply add to the DataAdapter
Also, as it coded now, you don't need the DataAdapter at all.

Dim connection As New Data.SqlClient.SqlConnection
Dim command As New Data.SqlClient.SqlCommand

connection.ConnectionString = "Server= server; Database= DB; integrated security=true"
command.CommandText = "INSERT INTO <table> (Col1, Col2, Col3, Col4) VALUES (@Name, @Property, @Value, @Date)"

command.Parameters.Add("@ServerName", SqlDbType.VarChar)
command.Parameters.Add("@Property", SqlDbType.VarChar)
command.Parameters.Add("@Value", SqlDbType.VarChar)
command.Parameters.Add("@CaptureDate", SqlDbType.DateTime)
command.Connection = connection

For i As Integer = 0 To DataGridView.Rows.Count - 1
    command.Parameters(0).Value = dgvServerConfig.Rows(i).Cells(0).Value
    command.Parameters(1).Value = dgvServerConfig.Rows(i).Cells(1).Value
    command.Parameters(2).Value = dgvServerConfig.Rows(i).Cells(2).Value
    command.Parameters(3).Value = dgvServerConfig.Rows(i).Cells(3).Value

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
G ScottAuthor Commented:
Isn't that an INSERT query.  I am looking to do an update.  For instance, they may just change a person's title in the DB.  I don't want to Insert a new record for this as I will have numerous records for the same person.  I just want to run an update.
G ScottAuthor Commented:
This didn't work and it has been months so I just want to close this question to get it off my 'open questions' list.  Thanks anyway.
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.