|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Saving data in a datatableSub 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? Kevin,
The point is here the dataadapter, that has to have commands, that includes the working of the update, delete and insert as is used by SQL. If you have made the dataadapter in any generic way, then the problem is probably alone in your acceptchanges. It means something as: "set the rows in the dataadapter updated in the database and accept the changes as done correct". Therefore those rows will never been updated in your code. (The dataadapter does this automaticly for you so there is not really need for that). Cor Show quoteHide quote "Kevin" <kmahoney@nospam_fireacademy.org> schreef in bericht news:kb4uk3tn7j0fr6r8q0ul1cn9oa91m20ae8@4ax.com... > 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? So, what does that mean in terms of code? Am I missing something or coding something incorrectly?
Show quoteHide quote On Thu, 29 Nov 2007 22:00:19 +0100, "Cor Ligthert[MVP]" <notmyfirstn***@planet.nl> wrote: >Kevin, > >The point is here the dataadapter, that has to have commands, that includes >the working of the update, delete and insert as is used by SQL. If you have >made the dataadapter in any generic way, then the problem is probably alone >in your acceptchanges. > >It means something as: "set the rows in the dataadapter updated in the >database and accept the changes as done correct". Therefore those rows will >never been updated in your code. (The dataadapter does this automaticly for >you so there is not really need for that). > >Cor > >"Kevin" <kmahoney@nospam_fireacademy.org> schreef in bericht >news:kb4uk3tn7j0fr6r8q0ul1cn9oa91m20ae8@4ax.com... >> 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?
remember a forms position on the screen
how to call Change() with System.Threading.Timer Setting SelectedItem of ComboBox programatically not working How does a project find dlls that it uses - where do I put them? If Statement, Please Help bold selected text Urgent: XP, Vista logoff application (WM_QUERYENDSESSION) List Boxes Visual Studio 2008 Power Packs SettingsProvider issue [VB.NET 2005] |
|||||||||||||||||||||||