I have a WPF app written using XAML and VB where I've used a Datagrid control to pull in my database data. The data pulls in great, and I can make changes within the cells as desired; however, those changes are not committed back to the database. I would like any changes made to save to the database as well.
Here is my XAML:
<DataGrid x:Name="RecordsDataGrid" CanUserAddRows="False" HorizontalAlignment="Left" Height="234" Margin="67,214,0,0" VerticalAlignment="Top" Width="1067" Background="#FFE0E0E0" AlternatingRowBackground="PaleGoldenrod" AlternationCount="2" HorizontalGridLinesBrush="LightGray" VerticalGridLinesBrush="LightGray"/>
Here is the VB:
Private Sub RecordsWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
Dim myConn As New SqlConnection
[...]
Dim query As String
query = "SELECT id as 'ID', company as 'Company' FROM dB ORDER BY id"
Dim command As New SqlCommand(query, myConn)
command.CommandType = System.Data.CommandType.Text
Dim dA As New SqlDataAdapter(command)
Dim dT As New DataTable
dA.Fill(dT)
RecordsDataGrid.ItemsSource = dT.AsDataView
End Sub
What I have tried:
I believe I can accomplish this via the UpdateCommand, but all solutions I have found are written in C# rather than VB (
example):
Private Sub RecordsWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
Dim myConn As New SqlConnection
[...]
Dim query As String
query = "SELECT id as 'ID', company as 'Company' FROM dB ORDER BY id"
Dim command As New SqlCommand(query, myConn)
command.CommandType = System.Data.CommandType.Text
Dim dA As New SqlDataAdapter(command)
Dim dT As New DataTable
dA.Fill(dT)
dA.Update(dT)
RecordsDataGrid.ItemsSource = dT.AsDataView
End Sub
But all conversions I have tried have not been successful.
Thank you in advance!