473,394 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

copy dataset (origin oracle) to access database

Hi,

I have a dataset "Mydataset" which contains of a few fields. (lets say
dept_id and dept_name)
A user can select several of these, and i want to export this to an access
database.

I have a database with one table (dept) and identical colums as the dataset.
But i can't figure out how to get the dataset into the database.

Here is what i've tried:

// This fill the dataset with records.
Uitwissel ldtsUitwissel =
(Uitwissel)selectie.GetSelectieExport(selectie.Use rnaam, i_count);
// to check my dataset i tried:
ldtsUitwissel.WriteXml("c:\myfile.xml");

// Get a new destination
lstrDestination = pstrPath + "\\Import\\" + Guid.NewGuid().ToString() +
".mdb";

// Pre made access database with existing table
string lstrSrc=pstrPath + "\\Import\\EmptyExchange.mdb";

// Copy the file
File.Copy(lstrSrc,lstrDestination,false);

OleDbConnection lodcConn = new OleDbConnection();
lodcConn.ConnectionString =
String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Da ta Source={0}",
lstrDestination);
lodcConn.Open();

OleDbDataAdapter lodaAcces = new OleDbDataAdapter(@"Select dept_id,
dept_name from dept", lodcConn);

lodaAcces.InsertCommand = new OleDbCommand();
lodaAcces.InsertCommand.Connection = lodcConn;

lodaAcces.InsertCommand.CommandText = @"INSERT INTO Dept (dept_id,
dept_name) VALUES (?, ?)";
lodaAcces.InsertCommand.Parameters.Add(new
System.Data.OleDb.OleDbParameter("dept_id",
System.Data.OleDb.OleDbType.Integer, 0, "dept_id"));
lodaAcces.InsertCommand.Parameters.Add(new
System.Data.OleDb.OleDbParameter("dept_name",
System.Data.OleDb.OleDbType.VarWChar, 60, "dept_name"));

lodaAcces.TableMappings.AddRange(new System.Data.Common.DataTableMapping[]
{
new System.Data.Common.DataTableMapping("Table", "BeverExport", new
System.Data.Common.DataColumnMapping[]
{
new System.Data.Common.DataColumnMapping("dept_id", "dept_id"),
new System.Data.Common.DataColumnMapping("dept_name", "dept_name"),
})
});
lodaAcces.Update(ldtsUitwissel, "Dept");

if i open the access database i stil have an empty table dept
if i open the file c:\myfile.xml it's filled

Who can fix this? (or has an entire new idea to copy the dataset)
Nov 16 '05 #1
1 6654
http://www.knowdotnet.com/articles/datasetmerge.html

--

W.G. Ryan, eMVP

http://forums.devbuzz.com/
http://www.knowdotnet.com/williamryan.html
http://www.msmvps.com/WilliamRyan/
"Jeroen Pot" <jm****@quicknet.nl> wrote in message
news:c4***************************@news.multikabel .nl...
Hi,

I have a dataset "Mydataset" which contains of a few fields. (lets say
dept_id and dept_name)
A user can select several of these, and i want to export this to an access
database.

I have a database with one table (dept) and identical colums as the dataset. But i can't figure out how to get the dataset into the database.

Here is what i've tried:

// This fill the dataset with records.
Uitwissel ldtsUitwissel =
(Uitwissel)selectie.GetSelectieExport(selectie.Use rnaam, i_count);
// to check my dataset i tried:
ldtsUitwissel.WriteXml("c:\myfile.xml");

// Get a new destination
lstrDestination = pstrPath + "\\Import\\" + Guid.NewGuid().ToString() +
".mdb";

// Pre made access database with existing table
string lstrSrc=pstrPath + "\\Import\\EmptyExchange.mdb";

// Copy the file
File.Copy(lstrSrc,lstrDestination,false);

OleDbConnection lodcConn = new OleDbConnection();
lodcConn.ConnectionString =
String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Da ta Source={0}",
lstrDestination);
lodcConn.Open();

OleDbDataAdapter lodaAcces = new OleDbDataAdapter(@"Select dept_id,
dept_name from dept", lodcConn);

lodaAcces.InsertCommand = new OleDbCommand();
lodaAcces.InsertCommand.Connection = lodcConn;

lodaAcces.InsertCommand.CommandText = @"INSERT INTO Dept (dept_id,
dept_name) VALUES (?, ?)";
lodaAcces.InsertCommand.Parameters.Add(new
System.Data.OleDb.OleDbParameter("dept_id",
System.Data.OleDb.OleDbType.Integer, 0, "dept_id"));
lodaAcces.InsertCommand.Parameters.Add(new
System.Data.OleDb.OleDbParameter("dept_name",
System.Data.OleDb.OleDbType.VarWChar, 60, "dept_name"));

lodaAcces.TableMappings.AddRange(new System.Data.Common.DataTableMapping[]
{
new System.Data.Common.DataTableMapping("Table", "BeverExport", new
System.Data.Common.DataColumnMapping[]
{
new System.Data.Common.DataColumnMapping("dept_id", "dept_id"),
new System.Data.Common.DataColumnMapping("dept_name", "dept_name"),
})
});
lodaAcces.Update(ldtsUitwissel, "Dept");

if i open the access database i stil have an empty table dept
if i open the file c:\myfile.xml it's filled

Who can fix this? (or has an entire new idea to copy the dataset)

Nov 16 '05 #2

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

Similar topics

3
by: Jon Ole Hedne | last post by:
My Access 2002-application need to work with tables from both Oracle and Access. To solve this, I want to run some querys on three views in Oracle and import the results into temporary...
2
by: Simon Harvey | last post by:
Hi everyone, I was wondering if it is possible, to use SQL to return more than one table at a time into a dataset. I only know the basics of SQL and so I'm not sure if I'm just asking a stupid...
3
by: Marnie | last post by:
Hi there I am new to VB.Net (formerly a Centura 'Gupta' programmer) and just trying to do a simple excercise out of the help to populate a couple of text fields on a form by using a parameterized...
4
by: Lee Moore | last post by:
I am trying to develop a threaded function to create a dataset from an Oracle database. When querying an elaborate view, queries take a while. I would like to place and animated wait dialog up...
4
by: JIM.H. | last post by:
Hello, I am trying to write the data I got from a web service to my table in SQL Server I need to append the dataset wsDS to the dataset ds and do update. PVS.myWS.Loader load = new...
5
by: John | last post by:
Hi, I am developing a windows app using C# 2005. This app uses SQL Server or Oracle database depending on the what the user is using. Can I create one typed dataset and use it for SQL Server and...
2
by: =?Utf-8?B?aGVuZm8=?= | last post by:
Hi, I am working on program to cop data from the main database (Oracle or SQL Server) to a local Access-database used on laptops. The databse is quite large so the routine nedds to be fast. The...
0
by: Mdotnetdeveloper | last post by:
hi, i am trying to achieve this: i have 2 different databses. i need to get data from one databse (for eg. in a datset), copy it into another dateset (pointing to the second database), make...
1
by: igurov | last post by:
Hi, I want to copy access tables to oracle database. Till now I have opened the connections to both of them. Can anyone explain me what are the next steps? Here is the code that I wrote till now:...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
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...
1
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...
0
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
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
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,...
0
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...
0
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 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.