Solved

one dataset table to multiple dataset table...

Posted on 2006-11-17
6
182 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now