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?
public void CopyDataSet(int start, int end)
{
OleDbDataAdapter sourceAdapter = new OleDbDataAdapter("SELECT * FROM [nguoi
su dung dat] " +
"WHERE ID > " + (start - 1).ToString() +
" AND [nguoi su dung dat].id < " + (end + 1).ToString(), connectionString
+ sourceMDB);
DataSet sourceDataSet = new DataSet("nguoi su dung dat");
sourceAdapter.Fill(sourceDataSet);
OleDbDataAdapter destAdapter = new OleDbDataAdapter("SELECT * FROM [nguoi
su dung dat]",
connectionString + destinationMDB);
OleDbCommandBuilder builder = new OleDbCommandBuilder(destAdapter);
DataSet destDataSet = sourceDataSet.Clone();
destDataSet.Merge(sourceDataSet); // Same as sourceDataSet
destAdapter.Update(destDataSet); // Nothing updated :(
}
Thanks
--
XP Pro SP2, .NET v1.1, VS.NET 2003 2 3797
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*****@hotmail.com> wrote in message
news:b8*************************@news.microsoft.co m... 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?
public void CopyDataSet(int start, int end) { OleDbDataAdapter sourceAdapter = new OleDbDataAdapter("SELECT * FROM [nguoi su dung dat] " + "WHERE ID > " + (start - 1).ToString() + " AND [nguoi su dung dat].id < " + (end + 1).ToString(), connectionString + sourceMDB); DataSet sourceDataSet = new DataSet("nguoi su dung dat"); sourceAdapter.Fill(sourceDataSet);
OleDbDataAdapter destAdapter = new OleDbDataAdapter("SELECT * FROM [nguoi su dung dat]", connectionString + destinationMDB); OleDbCommandBuilder builder = new OleDbCommandBuilder(destAdapter); DataSet destDataSet = sourceDataSet.Clone(); destDataSet.Merge(sourceDataSet); // Same as sourceDataSet destAdapter.Update(destDataSet); // Nothing updated :( }
Thanks
--
XP Pro SP2, .NET v1.1, VS.NET 2003
Hi,
[inline]
"Son Ha" <so*****@hotmail.com> wrote in message
news:b8*************************@news.microsoft.co m... 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?
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(sourceDataSet)", you first set
sourceAdapter.AcceptChangesDuringFill = false;
--- OR ---
2) Manually insert each row using BeginLoadData, LoadDataRow & EndLoadData
something like:
destTable.BeginLoadData();
foreach ( DataRow dr in sourceTable.Rows )
destTable.LoadDataRow( dr.ItemArray, false );
destTable.EndLoadData();
HTH,
Greetings public void CopyDataSet(int start, int end) { OleDbDataAdapter sourceAdapter = new OleDbDataAdapter("SELECT * FROM [nguoi su dung dat] " + "WHERE ID > " + (start - 1).ToString() + " AND [nguoi su dung dat].id < " + (end + 1).ToString(), connectionString + sourceMDB); DataSet sourceDataSet = new DataSet("nguoi su dung dat"); sourceAdapter.Fill(sourceDataSet);
OleDbDataAdapter destAdapter = new OleDbDataAdapter("SELECT * FROM [nguoi su dung dat]", connectionString + destinationMDB); OleDbCommandBuilder builder = new OleDbCommandBuilder(destAdapter); DataSet destDataSet = sourceDataSet.Clone(); destDataSet.Merge(sourceDataSet); // Same as sourceDataSet destAdapter.Update(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...
|
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...
|
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...
|
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:
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |