473,503 Members | 2,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OleDbDataAdapter - merging two tables

Hello,

I am trying to plonk the entire contents of a dBase file into an
Access table.

I have scanned the dBase fields and created an empty Access table with
the same field formats.
I have also created oledb connections to both data sources.

Below is my attempt at achieving this, which doesn't work. I've
googled all day and had lots of clues but not found any code that
works for me. I think I'm close but obviously missing something quite
important.

It would be much appreciated if anyone could tell me what it is?
Private Sub test()

Dim strquerySource As String = "Select * from dBaseFile"
Dim strqueryDestination As String = "Select * from
accessTable"

Dim daSource As OleDbDataAdapter
Dim daDestination As OleDbDataAdapter

Dim tableSource As New DataTable
Dim tableDestination As New DataTable

daSource = New OleDbDataAdapter(strquerySource, cnDBASE)

'if line below is NOT used then no error but no update.
'if it IS used then get error as commented later.
daSource.AcceptChangesDuringFill = False

daSource.Fill(tableSource)

'to visually check data - ITS OK, displays all data
Me.DataGridViewDBASE.DataSource = tableSource
Me.DataGridViewDBASE.Refresh()
'destination
daDestination = New OleDbDataAdapter(strqueryDestination,
cnAccess)
daDestination.Fill(tableDestination)

'to visually check data - ITS OK, just shows headers
Me.DataGridViewAccess.DataSource = tableDestination
Me.DataGridViewAccess.Refresh()

'ERROR - IF daSource.AcceptChangesDuringFill = False
' "Update requires a valid InsertCommand when passed DataRow
collection with new rows."
' otherwisae no error but the Access table doesn't get
updated.

daDestination.Update(tableSource)
End Sub
Jun 27 '08 #1
6 1669
You can construct a system.drawing.point from the x and y co-ordinates so
you could save them as either a single string or as two seperate fields. I
would save each as a seperate field as it would be easier to report upon.

However, if you want to store them as two strings (or one string) the code
below shows how to reconstruct the system.drawing.point from a comma
seperated string.

Kind regards,

Rob
Code follows:

Dim sLocation As String = ""

sLocation = Me.Location.X.ToString + "," + Me.Location.Y.ToString

Me.Location = New System.Drawing.Point(0, 0)
MsgBox("moved")

Me.Location = New System.Drawing.Point(Split(sLocation, ",")(0),
Split(sLocation, ",")(1))
MsgBox("moved back")

"baldrick" <ph**********@hotmail.comwrote in message
news:54**********************************@m44g2000 hsc.googlegroups.com...
Hello,

I am trying to plonk the entire contents of a dBase file into an
Access table.

I have scanned the dBase fields and created an empty Access table with
the same field formats.
I have also created oledb connections to both data sources.

Below is my attempt at achieving this, which doesn't work. I've
googled all day and had lots of clues but not found any code that
works for me. I think I'm close but obviously missing something quite
important.

It would be much appreciated if anyone could tell me what it is?
Private Sub test()

Dim strquerySource As String = "Select * from dBaseFile"
Dim strqueryDestination As String = "Select * from
accessTable"

Dim daSource As OleDbDataAdapter
Dim daDestination As OleDbDataAdapter

Dim tableSource As New DataTable
Dim tableDestination As New DataTable

daSource = New OleDbDataAdapter(strquerySource, cnDBASE)

'if line below is NOT used then no error but no update.
'if it IS used then get error as commented later.
daSource.AcceptChangesDuringFill = False

daSource.Fill(tableSource)

'to visually check data - ITS OK, displays all data
Me.DataGridViewDBASE.DataSource = tableSource
Me.DataGridViewDBASE.Refresh()
'destination
daDestination = New OleDbDataAdapter(strqueryDestination,
cnAccess)
daDestination.Fill(tableDestination)

'to visually check data - ITS OK, just shows headers
Me.DataGridViewAccess.DataSource = tableDestination
Me.DataGridViewAccess.Refresh()

'ERROR - IF daSource.AcceptChangesDuringFill = False
' "Update requires a valid InsertCommand when passed DataRow
collection with new rows."
' otherwisae no error but the Access table doesn't get
updated.

daDestination.Update(tableSource)
End Sub
Jun 27 '08 #2
Greetings,

I have observed that you can only use a DataAdapter to read data from an
Access table, but you can't Insert data to an Access table (or Update)
using an OleDataAdapter. Some reading I have done on this suggests that
this is intentional. So, the workaround that I have come up with is to
loop through your rows and insert each row individually using a straight
forward SelectCommand

For Each dr As DataRow In yourDataTable
da.SelectCommand.CommandText = "Insert Into AccessTbl Select '" &
dr("fld1").ToString & "','" & dr("fld2").ToString & "','" &
dr("fld3").ToString & "'," & ...
da.SelectCommand.ExecuteNonQuery
Next

You will have to delimit as required (single quotes for Text fields, and
probably for Date fields).

This may seem like a bit of a pain, but I feel that Microsoft is trying
to steer .Net away from Access -- keeping Access as a File-based com
system. I may be wrong, and if I am, hopefully someone else knows how
to use an OleDataAdapter Insert (and Update) command with Access.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #3
One Correction:

yourDataTable.Rows '--I forgot the .Rows part

For Each dr As DataRow In yourDataTable.Rows
da.SelectCommand.CommandText = "Insert Into AccessTbl Select '" &
dr("fld1").ToString & "','" &
dr("fld2").ToString & "','" & dr("fld3").ToString & "',"
& ...
da.SelectCommand.ExecuteNonQuery
Next


Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #4
On 27 May, 22:14, Rich P <rpng...@aol.comwrote:
Greetings,

I have observed that you can only use a DataAdapter to read data from an
Access table, but you can't Insert data to an Access table (or Update)
using an OleDataAdapter. *Some reading I have done on this suggests that
this is intentional. *So, the workaround that I have come up with is to
loop through your rows and insert each row individually using a straight
forward SelectCommand

For Each dr As DataRow In yourDataTable
* da.SelectCommand.CommandText = "Insert Into AccessTbl Select '" &
dr("fld1").ToString & "','" & dr("fld2").ToString & "','" &
dr("fld3").ToString & "'," & ...
* da.SelectCommand.ExecuteNonQuery
Next

You will have to delimit as required (single quotes for Text fields, and
probably for Date fields).

This may seem like a bit of a pain, but I feel that Microsoft is trying
to steer .Net away from Access -- keeping Access as a File-based com
system. *I may be wrong, and if I am, hopefully someone else knows how
to use an OleDataAdapter Insert (and Update) command with Access.

Rich

*** Sent via Developersdexhttp://www.developersdex.com***
Is it just Access? Are you saying that if the destination table was
SQL Server that it would work?

The code I'm going off is...

http://www.knowdotnet.com/articles/datasetmerge.html

Jun 27 '08 #5
I mean just Access. Last year I wrote DLL (VB2005 and C#)which I
explosed to the Com environment which used OLE and Sql DataAdapters for
manipulating data. I made references to this DLL from Access 2003 and
Excel 2003. The DLL worked fine with Excel but would error out when
used with Access. So I modified the DLL to read from a text file (I
would export data to a text file from Access) - then the DLL worked OK
from Access. So I deduced that it was the DataAdapter which did not
work with Access. I posted some questions on this, and someone (a tech
author) got back to me and suggested that this was intentional.

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Jun 27 '08 #6
Baldrick,

Please don't multipost, it is not my purpose to post multiple answers in
every newsgroup.

Use crossposting next time, which is sending the same message to all
newsgroups, that can be about your question.

We can then see if your question is already answered.

Thanks in advance.

Cor

"baldrick" <ph**********@hotmail.comschreef in bericht
news:54**********************************@m44g2000 hsc.googlegroups.com...
Hello,

I am trying to plonk the entire contents of a dBase file into an
Access table.

I have scanned the dBase fields and created an empty Access table with
the same field formats.
I have also created oledb connections to both data sources.

Below is my attempt at achieving this, which doesn't work. I've
googled all day and had lots of clues but not found any code that
works for me. I think I'm close but obviously missing something quite
important.

It would be much appreciated if anyone could tell me what it is?
Private Sub test()

Dim strquerySource As String = "Select * from dBaseFile"
Dim strqueryDestination As String = "Select * from
accessTable"

Dim daSource As OleDbDataAdapter
Dim daDestination As OleDbDataAdapter

Dim tableSource As New DataTable
Dim tableDestination As New DataTable

daSource = New OleDbDataAdapter(strquerySource, cnDBASE)

'if line below is NOT used then no error but no update.
'if it IS used then get error as commented later.
daSource.AcceptChangesDuringFill = False

daSource.Fill(tableSource)

'to visually check data - ITS OK, displays all data
Me.DataGridViewDBASE.DataSource = tableSource
Me.DataGridViewDBASE.Refresh()
'destination
daDestination = New OleDbDataAdapter(strqueryDestination,
cnAccess)
daDestination.Fill(tableDestination)

'to visually check data - ITS OK, just shows headers
Me.DataGridViewAccess.DataSource = tableDestination
Me.DataGridViewAccess.Refresh()

'ERROR - IF daSource.AcceptChangesDuringFill = False
' "Update requires a valid InsertCommand when passed DataRow
collection with new rows."
' otherwisae no error but the Access table doesn't get
updated.

daDestination.Update(tableSource)
End Sub
Jun 27 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
4910
by: svdh | last post by:
I have posed a question last saturday and have advanced alot in the meantime. But I am still not there Problem is that I try to merging various fields from various tables in one document in Word...
2
3805
by: Son Ha | last post by:
I want to copy some record from a Access database to another Access DB. My code as follow but not working. The destAdapter.Update() return 0 record affected. Tell me what's wrong in my code? ...
2
1343
by: Dan Cooper | last post by:
I've got two datasets, each containing a single data table. dstDataSetA.Tables("TableA") dstDataSetB.Tables("TableB") I want to merge them together and delete any non-matching rows. ...
0
5797
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database...
7
1755
by: Jon Vaughan | last post by:
I have 2 datasets , one returned as a dataset from a webservice and one created client side form the same stored procedure that is returned from the webservice. I then try and merge the data, but...
1
3390
by: actimel01 | last post by:
I know this question has been asked many times before but I can't find an answer that fits my data! I have two Access databases. The tables in each have the exactly the same fields except for one...
1
1583
by: explode | last post by:
I made a oledbdataadapter with this code Public Sub Novo(ByVal nova1 As String, ByVal nova2 As String) Dim i As Integer Dim nova As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter Dim veza...
2
2904
by: explode | last post by:
I made nova oledbdataadapter select update insert and delete command and connection veza. dataset is Studenti1data, I made it by the new data source wizard,and made datagridview and bindingsource...
0
1177
by: =?Utf-8?B?QmFkaXM=?= | last post by:
Hi, I'm trying to do mail merging in C#.NET and in one methods: Word.Application wrdApp; Word._Document wrdDoc; Object oMissing = System.Reflection.Missing.Value; Object oFalse = false; ...
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7353
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7011
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
4689
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3180
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3170
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
401
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.