troubleshooting Question

Doing a one-to-many insert in C#

Avatar of tmitch68
tmitch68 asked on
2 Comments2 Solutions332 ViewsLast Modified:

I'm trying to do a one-to-many insert in an ASP.Net web site that uses C# as the code-behind-the-solution.

The first insert into the main table is easy.  First I set up the table to have a primary key that is auto-incremented.  Then, I just do the insert like so...

SqlDataSource1.InsertCommand = "INSERT INTO [RequestTable] ([DateSubmitted], [ReferringPhysician]) VALUES ('11/11/12', 'Dr. Spock')";

and the primary key is automatically generated.

Next, I have a table that has as its first column the primary key from the first table, and then a specific value for the second.

My problem is - how do I get the automatically-generated primary key value from the first insert in order to make an insertion into the second table?

Thanks in advance,
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros