473,847 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

OleDbDataAdapte r question


I want to copy some record from a Access database to another Access DB. My
code as follow but not working. The destAdapter.Upd ate() return 0 record
affected.
Tell me what's wrong in my code?

public void CopyDataSet(int start, int end)
{
OleDbDataAdapte r sourceAdapter = new OleDbDataAdapte r("SELECT * FROM [nguoi
su dung dat] " +
"WHERE ID > " + (start - 1).ToString() +
" AND [nguoi su dung dat].id < " + (end + 1).ToString(), connectionStrin g
+ sourceMDB);
DataSet sourceDataSet = new DataSet("nguoi su dung dat");
sourceAdapter.F ill(sourceDataS et);

OleDbDataAdapte r destAdapter = new OleDbDataAdapte r("SELECT * FROM [nguoi
su dung dat]",
connectionStrin g + destinationMDB) ;
OleDbCommandBui lder builder = new OleDbCommandBui lder(destAdapte r);
DataSet destDataSet = sourceDataSet.C lone();
destDataSet.Mer ge(sourceDataSe t); // Same as sourceDataSet
destAdapter.Upd ate(destDataSet ); // Nothing updated :(
}

Thanks
--

XP Pro SP2, .NET v1.1, VS.NET 2003
Nov 17 '05 #1
2 3824
Hi,

I would rather use a DataReader to read the records and at the same time
inserting these records in the second DB.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Son Ha" <so*****@hotmai l.com> wrote in message
news:b8******** *************** **@news.microso ft.com...

I want to copy some record from a Access database to another Access DB. My
code as follow but not working. The destAdapter.Upd ate() return 0 record
affected.
Tell me what's wrong in my code?

public void CopyDataSet(int start, int end)
{
OleDbDataAdapte r sourceAdapter = new OleDbDataAdapte r("SELECT * FROM
[nguoi su dung dat] " +
"WHERE ID > " + (start - 1).ToString() +
" AND [nguoi su dung dat].id < " + (end + 1).ToString(), connectionStrin g
+ sourceMDB);
DataSet sourceDataSet = new DataSet("nguoi su dung dat");
sourceAdapter.F ill(sourceDataS et);

OleDbDataAdapte r destAdapter = new OleDbDataAdapte r("SELECT * FROM [nguoi
su dung dat]",
connectionStrin g + destinationMDB) ;
OleDbCommandBui lder builder = new OleDbCommandBui lder(destAdapte r);
DataSet destDataSet = sourceDataSet.C lone();
destDataSet.Mer ge(sourceDataSe t); // Same as sourceDataSet
destAdapter.Upd ate(destDataSet ); // Nothing updated :(
}

Thanks
--

XP Pro SP2, .NET v1.1, VS.NET 2003

Nov 17 '05 #2
Hi,
[inline]

"Son Ha" <so*****@hotmai l.com> wrote in message
news:b8******** *************** **@news.microso ft.com...

I want to copy some record from a Access database to another Access DB. My
code as follow but not working. The destAdapter.Upd ate() return 0 record
affected.
Tell me what's wrong in my code?
The problem is that after a normal Fill operation all rowstates will be
"unmodified ", merging it with the dest dataset doesn't change their state,
so when you update nothing happens because all rows are marked as
"unmodified ".

So you have to make sure that the rows have an "added" rowstate :

1) Before you call "sourceAdapter. Fill(sourceData Set)", you first set
sourceAdapter.A cceptChangesDur ingFill = false;

--- OR ---

2) Manually insert each row using BeginLoadData, LoadDataRow & EndLoadData
something like:

destTable.Begin LoadData();
foreach ( DataRow dr in sourceTable.Row s )
destTable.LoadD ataRow( dr.ItemArray, false );
destTable.EndLo adData();
HTH,
Greetings


public void CopyDataSet(int start, int end)
{
OleDbDataAdapte r sourceAdapter = new OleDbDataAdapte r("SELECT * FROM
[nguoi su dung dat] " +
"WHERE ID > " + (start - 1).ToString() +
" AND [nguoi su dung dat].id < " + (end + 1).ToString(), connectionStrin g
+ sourceMDB);
DataSet sourceDataSet = new DataSet("nguoi su dung dat");
sourceAdapter.F ill(sourceDataS et);

OleDbDataAdapte r destAdapter = new OleDbDataAdapte r("SELECT * FROM [nguoi
su dung dat]",
connectionStrin g + destinationMDB) ;
OleDbCommandBui lder builder = new OleDbCommandBui lder(destAdapte r);
DataSet destDataSet = sourceDataSet.C lone();
destDataSet.Mer ge(sourceDataSe t); // Same as sourceDataSet
destAdapter.Upd ate(destDataSet ); // Nothing updated :(
}

Thanks
--

XP Pro SP2, .NET v1.1, VS.NET 2003

Nov 17 '05 #3

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

Similar topics

1
2553
by: jtsree | last post by:
i am using Visual Studio.net professional 2003 (VisualBasic.net).I am building a very very simple project where i need to connect to Microsoft access database through OledbDataAdapter in design mode by Dragging the OledbDataAdapter Control from the Data tab on the ToolBox and then generate the DataSet. I am able to connect to MS ACCESS and test connection is succedded.Now when i try to generate the Dataset by Right Clicking The Data...
1
475
by: jtsree | last post by:
I am Using (Windows XP) Visual Studio.net 2003 professional edition working on VB.net language. I am bulding a very very simple project in VB.net where i connect to Access Database by dragging OledbDataAdapter tool from the Data tab of the Toolbox. When OledbDataAdapter has been added to the Component tray i am able to generate a connection to Access database and generate Connection object and also the Test Connection has Succeeded. Now...
1
3741
by: bob | last post by:
Hi.. I'm making a OleDb connection to a access database.. I can fill the dataset fine and view the data, but when I add a new row and try to update the db I get this error. Any help would be appreciated.. Error: An unhandled exception of type "System.Data.OleDb.OleDbException' occurred in system.data.dll This error is from the following line:
1
5097
by: Bennett Haselton | last post by:
Suppose I add a new row to a table in a dataset, and then I use an OleDbDataAdapter to add that new row to a SQL Server database using OleDbDataAdapter.Update(), as in the following code: dsLocalDataSet.user_postRow newRow = dsLocalDataSet1.user_post.Newuser_postRow(); newRow.post_text = this.lblHiddenMessageStorage.Text; newRow.post_datetime = System.DateTime.Now; dsLocalDataSet1.user_post.Adduser_postRow(newRow);...
4
3993
by: shachar | last post by:
hi all(i tried yesterday but it didnt work). i wrote this code and i get an error msg: Private Pr_MyCon As System.Data.OleDb.OleDbConnection Private Pr_DataSet As DataSet Private Pr_DataAdapter As System.Data.OleDb.OleDbDataAdapter Pr_MyCon = New System.Data.OleDb.OleDbConnection Pr_DataSet = New DataSet("Temp") Pr_MyCon.ConnectionString = "..." Pr_DataAdapter = New OleDb.OleDbDataAdapter("select *
5
3702
by: Al | last post by:
Hi, I need to update tables in access 97. The table names have spaces (not my choice). My update fails even though I use the OleDbCommandBuilder. Here is a code I am using myDataAdapter = New OleDbDataAdapter myDataAdapter.SelectCommand = New OleDbCommand("Select * from ", MyConnection) Dim cb As OleDbCommandBuilder = New OleDbCommandBuilder(PatientsBillingDataAdapter)
6
14925
by: Marcel Hug | last post by:
Hi all ! I have a table in my database, which has 3 attributes. IDFailureControl, ControlDate and ControlVersion. In the following function I test, if the date of today allready exists. Then I would like to write the new ControlDate or Version into the database. First i update the dataset, then i create a Insertcommand and call the update-methode. All datas are in the database, but.... 1.) If I only use the InsertCommand, without...
6
1870
by: tom c | last post by:
I create 2 data OleDbDataAdapters, one with the wizard, and one in code. I know the adapter created in code is OK because I use it to fill a data table. However, when I try to use the same SQL insert statement in the two adapters, the adapter created with the wizard works fine, but the adapter created in code gives me an error "Object reference not set to an instance of an object". The code is below. What am I doing wrong? ...
6
1685
by: baldrick | last post by:
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
0
9727
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10981
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10643
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10706
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7879
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7050
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5716
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5907
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4521
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 we have to send another system

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.