|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
ImportRow() doesn't save changes to database tableI'm new to VB.NET and I'm trying to import some data from SQL Server to MS Access but cannot make it to work (note: I don't want to use DTS) .....goes like this... Dim daSql As New SqlDataAdapter("select * from table1", SqlConnection) Dim dsSql As New DataSet() ' to hold info from SQL Server daSql.Fill(dsSql, "table1") Dim daAcc As New OleDb.OleDbDataAdapter("select * from table2", AccessConnection) ' table2 is an empty table with the same schema as table1 Dim dsAcc As New DataSet() 'to hold info for Access daAcc.Fill(dsAcc, "table2") For i as Integer = 0 To dsSql.Tables(0).Rows.Count - 1 dsAcc.Tables(0).NewRow() dsAcc.Tables(0).ImportRow(dsSql.Tables(0).Rows(i)) Next i dsAcc.Tables(0).AcceptChanges(0 daAcc.AcceptChangesDuringUpdate = True daAcc.Update(dsAcc, "table2") '...end what am I doing wrong? messagebox inserted anywhere after For..Next loop shows desired number of rows in Access dataSet but the are no changes made to the actual database. mikus,
AcceptChanges is re-setting the rows to indicate no changes have been made. Try it without the AcceptChanges. Kerry Moorman Show quote "mikus" wrote: > Can anybody help me please. > I'm new to VB.NET and I'm trying to import some data from SQL Server to MS > Access but cannot make it to work (note: I don't want to use DTS) > ....goes like this... > > Dim daSql As New SqlDataAdapter("select * from table1", SqlConnection) > Dim dsSql As New DataSet() ' to hold info from SQL Server > daSql.Fill(dsSql, "table1") > > Dim daAcc As New OleDb.OleDbDataAdapter("select * from table2", > AccessConnection) > ' table2 is an empty table with the same schema as table1 > Dim dsAcc As New DataSet() 'to hold info for Access > daAcc.Fill(dsAcc, "table2") > > For i as Integer = 0 To dsSql.Tables(0).Rows.Count - 1 > dsAcc.Tables(0).NewRow() > dsAcc.Tables(0).ImportRow(dsSql.Tables(0).Rows(i)) > Next i > > dsAcc.Tables(0).AcceptChanges(0 > daAcc.AcceptChangesDuringUpdate = True > daAcc.Update(dsAcc, "table2") > > '...end > > what am I doing wrong? > messagebox inserted anywhere after For..Next loop shows desired number of > rows in Access dataSet but the are no changes made to the actual database. > > Thank you for such a prompt response however after removing AcceptChanges
from the code the result is still the same. Show quote "Kerry Moorman" wrote: > mikus, > > AcceptChanges is re-setting the rows to indicate no changes have been made. > > Try it without the AcceptChanges. > > Kerry Moorman > > > "mikus" wrote: > > > Can anybody help me please. > > I'm new to VB.NET and I'm trying to import some data from SQL Server to MS > > Access but cannot make it to work (note: I don't want to use DTS) > > ....goes like this... > > > > Dim daSql As New SqlDataAdapter("select * from table1", SqlConnection) > > Dim dsSql As New DataSet() ' to hold info from SQL Server > > daSql.Fill(dsSql, "table1") > > > > Dim daAcc As New OleDb.OleDbDataAdapter("select * from table2", > > AccessConnection) > > ' table2 is an empty table with the same schema as table1 > > Dim dsAcc As New DataSet() 'to hold info for Access > > daAcc.Fill(dsAcc, "table2") > > > > For i as Integer = 0 To dsSql.Tables(0).Rows.Count - 1 > > dsAcc.Tables(0).NewRow() > > dsAcc.Tables(0).ImportRow(dsSql.Tables(0).Rows(i)) > > Next i > > > > dsAcc.Tables(0).AcceptChanges(0 > > daAcc.AcceptChangesDuringUpdate = True > > daAcc.Update(dsAcc, "table2") > > > > '...end > > > > what am I doing wrong? > > messagebox inserted anywhere after For..Next loop shows desired number of > > rows in Access dataSet but the are no changes made to the actual database. > > > > |
|||||||||||||||||||||||