G Scott
asked on
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:
I have a button in said window that I would like to use to save any changes/additions/deletion s 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."
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.
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.
InitializeComponent()
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)
adapter.Fill(dt)
DataGrid1.ItemsSource = dt.DefaultView
DataGrid1.DataContext = dt
End Using
' Add any initialization after the InitializeComponent() call.
DataGrid1.SelectedItem = Nothing
End Sub
I have a button in said window that I would like to use to save any changes/additions/deletion
Using con As New SqlConnection(sqlconnXML)
Dim myBuilder As SqlCommandBuilder = New SqlCommandBuilder(adapter)
myBuilder.GetUpdateCommand()
adapter.UpdateCommand = myBuilder.GetUpdateCommand()
adapter.Update(dt)
End Using
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
ASKER