K
Kevin
I'm new to ADO.NET--trying to make the switch from ADO, which I've been using in my VB2005 apps up until now. Here's what I have:
Sub Save_Record()
Dim OldRecord as DataTable
Dim NewRecord as DataTable
Using testConnection As SqlConnection = New SqlConnection(SQLConnectionString)
Dim testCommand As SqlCommand = testConnection.CreateCommand()
testCommand.CommandText = "SELECT * FROM MasterRoster WHERE MR_StudentNumber = '" & txtStudentNumber.Text & "'"
Dim dataAdapter As New SqlDataAdapter(testCommand)
dataAdapter.Fill(OldRecord)
dataAdapter.Fill(NewRecord)
If NewRecord.Rows.Count = 0 Then
NewRecord.Rows.Add()
NewRecord.Rows(0).Item(53) = sysUser & " " & Now 'CreatedBy
End If
NewRecord.Rows(0).Item(0) = txtLName.Text
NewRecord.Rows(0).Item(1) = txtFName.Text
NewRecord.Rows(0).Item(2) = txtMI.Text
NewRecord.AcceptChanges()
dataAdapter.Update(NewRecord)
'Code to compare OldRecord to NewRecord cut from here
End Using
End Sub
Comparing the two datatables shows the changes I made, but the changes don't persist. How can I update the database with my changes?
Sub Save_Record()
Dim OldRecord as DataTable
Dim NewRecord as DataTable
Using testConnection As SqlConnection = New SqlConnection(SQLConnectionString)
Dim testCommand As SqlCommand = testConnection.CreateCommand()
testCommand.CommandText = "SELECT * FROM MasterRoster WHERE MR_StudentNumber = '" & txtStudentNumber.Text & "'"
Dim dataAdapter As New SqlDataAdapter(testCommand)
dataAdapter.Fill(OldRecord)
dataAdapter.Fill(NewRecord)
If NewRecord.Rows.Count = 0 Then
NewRecord.Rows.Add()
NewRecord.Rows(0).Item(53) = sysUser & " " & Now 'CreatedBy
End If
NewRecord.Rows(0).Item(0) = txtLName.Text
NewRecord.Rows(0).Item(1) = txtFName.Text
NewRecord.Rows(0).Item(2) = txtMI.Text
NewRecord.AcceptChanges()
dataAdapter.Update(NewRecord)
'Code to compare OldRecord to NewRecord cut from here
End Using
End Sub
Comparing the two datatables shows the changes I made, but the changes don't persist. How can I update the database with my changes?