473,387 Members | 1,742 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,387 software developers and data experts.

Join DataTables in same dataset

don
I have written a program to hold a sales contact db. It is written in c#
express.

an update is sent from head office in xl format, i need to import only the
new rows to an access database.

I have gotten this far:

a separate OleDbconnection to each source, which reads the entire data
source (select *) into the same dataset, but different tables.

from here i want to be able to pull the new rows from the xl table and
append it to the access table.

When I try to create a relation between the two table it says "This
constraint cannot be enabled as not all values have corresponding parent
values."
************************************************** ************************************************** ***************
DataColumn parentColumn =
accessdata.Tables["gnwestcustomers"].Columns["Customer Number"];

DataColumn childColumn = accessdata.Tables["Table"].Columns["Customer
Number"];

DataRelation relExcel;

relExcel = new DataRelation("RelateExcel", parentColumn, childColumn);
accessdata.Relations.Add(relExcel);

************************************************** ************************************************** ***********************************

I can do this all in MSAccess easily, but the user needs to be able to do it
in the field....come on people sales person here.......not technically
enabled in the computer department if you know what i mean... :)

any help appreciated.

Thanks in advance.
Nov 14 '06 #1
3 3044
Don,

As far as the framework is concerned, any two given DataTable objects
have different schemas. Even if they look the same to you, they're not
to the framework.

Your best bet here is probably to Merge() one DataTable into the other.
The Merge() process will deal with the issues like, "what if the
schemas are different," or, "what if the columns are in a different
order," and give you fine-grained control of how to deal with that. If
your assumption that the schemas are identical is correct, you'll get
no exceptions.

Once the data is merged, you'll have to separate what goes where. It
may be useful to add a source column (pre-merge) to each table that
contains a static value based on where it came from. Then it's much
easier to un-munge later.
Stephan
don wrote:
I have written a program to hold a sales contact db. It is written in c#
express.

an update is sent from head office in xl format, i need to import only the
new rows to an access database.

I have gotten this far:

a separate OleDbconnection to each source, which reads the entire data
source (select *) into the same dataset, but different tables.

from here i want to be able to pull the new rows from the xl table and
append it to the access table.

When I try to create a relation between the two table it says "This
constraint cannot be enabled as not all values have corresponding parent
values."
************************************************** ************************************************** ***************
DataColumn parentColumn =
accessdata.Tables["gnwestcustomers"].Columns["Customer Number"];

DataColumn childColumn = accessdata.Tables["Table"].Columns["Customer
Number"];

DataRelation relExcel;

relExcel = new DataRelation("RelateExcel", parentColumn, childColumn);
accessdata.Relations.Add(relExcel);

************************************************** ************************************************** ***********************************

I can do this all in MSAccess easily, but the user needs to be able to do it
in the field....come on people sales person here.......not technically
enabled in the computer department if you know what i mean... :)

any help appreciated.

Thanks in advance.
Nov 14 '06 #2
don
Thanks for the reply, I won't need to "unmerge" the data later. The Excel
sheet has all the contacts that currently reside in the DB plus new ones.
All I want to do is take the new customers and append to the database in
access.

Seems simple I want to take data from a DataTable and put it into an
existing access table. Even if i do merge the data in the c# project i
still have to get the dataset to update back to the database.

"ssamuel" <ss*****@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Don,

As far as the framework is concerned, any two given DataTable objects
have different schemas. Even if they look the same to you, they're not
to the framework.

Your best bet here is probably to Merge() one DataTable into the other.
The Merge() process will deal with the issues like, "what if the
schemas are different," or, "what if the columns are in a different
order," and give you fine-grained control of how to deal with that. If
your assumption that the schemas are identical is correct, you'll get
no exceptions.

Once the data is merged, you'll have to separate what goes where. It
may be useful to add a source column (pre-merge) to each table that
contains a static value based on where it came from. Then it's much
easier to un-munge later.
Stephan
don wrote:
>I have written a program to hold a sales contact db. It is written in c#
express.

an update is sent from head office in xl format, i need to import only
the
new rows to an access database.

I have gotten this far:

a separate OleDbconnection to each source, which reads the entire data
source (select *) into the same dataset, but different tables.

from here i want to be able to pull the new rows from the xl table and
append it to the access table.

When I try to create a relation between the two table it says "This
constraint cannot be enabled as not all values have corresponding parent
values."
************************************************* ************************************************** ****************
DataColumn parentColumn =
accessdata.Tables["gnwestcustomers"].Columns["Customer Number"];

DataColumn childColumn = accessdata.Tables["Table"].Columns["Customer
Number"];

DataRelation relExcel;

relExcel = new DataRelation("RelateExcel", parentColumn, childColumn);
accessdata.Relations.Add(relExcel);

************************************************* ************************************************** ************************************

I can do this all in MSAccess easily, but the user needs to be able to do
it
in the field....come on people sales person here.......not technically
enabled in the computer department if you know what i mean... :)

any help appreciated.

Thanks in advance.

Nov 15 '06 #3
don
I figured it out:

I needed to import an Excel spreadsheet into an access database. Here is
what i did:

..) create OleDbConnection to the Access DataBase.
..) used OleDbCommand to create a copy of the "customers" table in the access
DB.
..) used another OleDbCommand to delete the contents of the table in the DB.
..) create OleDbDataAdapter, with OleDbCommandBuilder associated to it,
Selected the empty table into a DataTable called 'blankTable'.
..) create OleDbConnection to the Excel file and copied contents to
'blankTable'.
..) run a foreach loop using DataRow, to change the RowState of each row in
'blankTable' to "Added".
..) called the GetInsertCommand for OleDbCommand builder.
..) called OleDbDataAdapter.update.

All rows in the DataTable are seen as "Added" and are therefore copied back
to the blank table in the database.
From there simply combined a SELECT INTO statement with LEFT JOIN to grab
the records that were unmatched in the original table and append them.
"don" <do********@shaw.cawrote in message
news:huM6h.318321$1T2.75467@pd7urf2no...
Thanks for the reply, I won't need to "unmerge" the data later. The
Excel sheet has all the contacts that currently reside in the DB plus new
ones. All I want to do is take the new customers and append to the
database in access.

Seems simple I want to take data from a DataTable and put it into an
existing access table. Even if i do merge the data in the c# project i
still have to get the dataset to update back to the database.

"ssamuel" <ss*****@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>Don,

As far as the framework is concerned, any two given DataTable objects
have different schemas. Even if they look the same to you, they're not
to the framework.

Your best bet here is probably to Merge() one DataTable into the other.
The Merge() process will deal with the issues like, "what if the
schemas are different," or, "what if the columns are in a different
order," and give you fine-grained control of how to deal with that. If
your assumption that the schemas are identical is correct, you'll get
no exceptions.

Once the data is merged, you'll have to separate what goes where. It
may be useful to add a source column (pre-merge) to each table that
contains a static value based on where it came from. Then it's much
easier to un-munge later.
Stephan
don wrote:
>>I have written a program to hold a sales contact db. It is written in
c#
express.

an update is sent from head office in xl format, i need to import only
the
new rows to an access database.

I have gotten this far:

a separate OleDbconnection to each source, which reads the entire data
source (select *) into the same dataset, but different tables.

from here i want to be able to pull the new rows from the xl table and
append it to the access table.

When I try to create a relation between the two table it says "This
constraint cannot be enabled as not all values have corresponding parent
values."
************************************************ ************************************************** *****************
DataColumn parentColumn =
accessdata.Tables["gnwestcustomers"].Columns["Customer Number"];

DataColumn childColumn = accessdata.Tables["Table"].Columns["Customer
Number"];

DataRelation relExcel;

relExcel = new DataRelation("RelateExcel", parentColumn, childColumn);
accessdata.Relations.Add(relExcel);

************************************************ ************************************************** *************************************

I can do this all in MSAccess easily, but the user needs to be able to
do it
in the field....come on people sales person here.......not technically
enabled in the computer department if you know what i mean... :)

any help appreciated.

Thanks in advance.


Nov 22 '06 #4

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

Similar topics

0
by: William Ryan | last post by:
At the risk of sounding like a Big 5 consultant, "It depends". 1) Strongly typed datasets rock, they are faster than untyped, use intellisense... but your reason for wanting to use them is...
2
by: Jade | last post by:
Hi, I just wanted to ask a quick question regarding datasets. I am creating 3 tables using a dataadapter. what i want to know is that is the relationship created between these datatables...
2
by: Scott Tenorman | last post by:
I am trying to "join" two existing DataTable objects based on related information without having to request the data from SQL again. Lets just say the DataTables are contained in a single DataSet....
1
by: Gene Ariani | last post by:
I have one dataset that contains two DataTables: DataTable1: Customer_ID 1
4
by: DraguVaso | last post by:
Hi, For my VB.NET application I have the following situation: 2 tables on my SQL Server: tblAccounts and tblRules. For each Account there are many Rules (so tblRules is linked to my tblAccounts...
4
by: Geoff | last post by:
Hi I'm hoping somebody can help me with the following problem that has occurred to me. Suppose I have two tables in an SQL Server database. Let's call these tables A and B. Assume that A has...
1
by: hangdee | last post by:
I have 2 datatables (get from database) inside a dataset. How can I create another datatable which is a result of Select tb1.xxx, tb2.yyy from table1 as tb1 left join table2 as tb2 on tb1.id =...
2
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vs2005 and .net 2.0 I used 2 DirectorySearchers to retrieve data from Active Directory and placed them in 2 dataset tables. I need to perform the SQL equuvakebt of join operation to...
0
by: StefanPienaar | last post by:
Hi Guys Is there any way in c# (or vb.net) to extract a datatable of data from a dataset with multiple datatables which has relationships set up (containing combined data from the datatables)? ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.