I have a form that has a datagridview and a table adapter that displays data from a SQL database. What I'd like to do is that when edits are made to the data in the datagrid, I'd like to post all of the data back to the table. I know that you can do that with a dataset and a data adapter, but I don't know how to do that with a table adapter. Here is the code for my page:
When people click on the Save Exception button, I'd like to save back to the update the database with the new data.
Thank you
VB.NET:
Public Class ExceptionEdit
Private Sub ExceptionEdit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'MDRDataSet.scratchpad3' table. You can move, or remove it, as needed.
Me.Scratchpad3TableAdapter.Fill(Me.MDRDataSet.scratchpad3)
End Sub
Private Sub SaveExceptionButton(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles saveexceptionsButton.Click
Dim oCmd2 As System.Data.SqlClient.SqlCommand
Dim oDr2 As System.Data.SqlClient.SqlDataReader
oCmd2 = New System.Data.SqlClient.SqlCommand
Try
With oCmd2
.Connection = New System.Data.SqlClient.SqlConnection("Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx")
.Connection.Open()
.CommandType = CommandType.StoredProcedure
.Parameters.AddWithValue("@payperiodstartdate", payperiodstartdate)
.Parameters.AddWithValue("@payperiodenddate", payperiodenddate)
.CommandText = "sp_exceptioncopy"
oDr2 = .ExecuteReader()
oCmd2.Connection.Close()
End With
Catch ex As Exception
MessageBox.Show(ex.Message)
oCmd2.Connection.Close()
End Try
ExceptionsFinal.Show()
End Sub
When people click on the Save Exception button, I'd like to save back to the update the database with the new data.
Thank you