473,695 Members | 1,630 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 3814
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
2541
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
3735
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
5085
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
3978
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
3689
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
14904
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
1859
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
1678
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
8623
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, 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...
0
8565
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
8822
tracyyun
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...
0
7656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6488
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
5837
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
4339
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...
2
2269
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1971
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.