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 2 3812
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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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:
|
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);...
|
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 *
| |
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)
|
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...
|
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?
...
|
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
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |