Solved

one dataset table to multiple dataset table...

Posted on 2006-11-17
6
185 Views
Last Modified: 2008-02-01
Hi,
I have a dataset datatable
select ORDER ,
DESCRIPTION,
FIRSTNAME,
LASTNAME,
ADDRESS,
ZIP
FROM Order
               I need to select only FIRSTNAME,LASTNAME,ADDRESS,ZIP and insert in to new table called CONTACTS which has identity column CONTACTKEY. Then i need to select order and description and insert in to new table ORDERS which has ORDERID as identity column with one more column CONTACTKEY which has a foreignkey relationship to order table so when i am inserting the rows for orders the same contactkey should be updated in to ORDERS table as we have the releationship then i need to insert into database
how to do that?
http://www.experts-exchange.com/Programming/Programming_Languages/C_Sharp/Q_22062573.html

Regards
Nanban
0
Comment
Question by:nanban
  • 2
6 Comments
 
LVL 15

Expert Comment

by:ozymandias
ID: 17971043
Create an insert statement for the contacts table insert into contacts (FIRSTNAME,LASTNAME,ADDRESS,ZIP) values (FIRSTNAME,LASTNAME,ADDRESS,ZIP).
Then get the identity that was created for that insert.
You can either do this by running Select @@IDENTITY which will get you the value of CONTACTKEY most recently created or, if your database does not support @@IDENTITY, do select Max(CONTACTKEY) from CONTACTS and that should get you the same value.

Now you have your contactkey value you can use it in the insert statement into the orders table.
0
 

Author Comment

by:nanban
ID: 17976858
I dont want to use insert statement. I want to select particular column from the dataset which has all the columns. how to do that?
0
 

Author Comment

by:nanban
ID: 18136798
The Problem is resolved
1.This is the one of the way to insert relational data
http://www.codeproject.com/cs/database/relationaladonet.asp?df=100&forumid=14883&exp=0&select=1113044

2. Another way is using enterprise libaray updatedataset method.
using updatedataset its not requires to insert record one by one. After setting the relation between the table (primarykey foreignkey) using datarelation, first insert the table which needs to return identity column value using stored procedure then insert the table which needs the value from previous insert. it will automatically update the column with the returned value.

Regards,
Nanban.
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18171235
PAQed with points refunded (125)

Computer101
EE Admin
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question