Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#ASP.NET
Hi,
I had to discuss a bit of conceptual problem here. The scenario is like this:
A user comes on my my website and creates a new profile. As the new profile is created, I tend to save the result in tow tables in datbase viz.
 
1. profiles
2. profiles_plugins
 
The 'id' in profiles table is self-generated and hence there is no problem in storing the data it in the profiles table
But at the same time, this self-generated id in table 1 has to be stored in table 2 (profiles_plugins) in the column profile_id.
Data reader cannot fetch the value from table while it is being generated.
 
So, basically the problem is how to fetch this self generated id from table1 to be saved in table 2 at the same time when the user submits his details.
Posted 31-Dec-10 20:07pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I hope the Self Generated ID column in Table Profile is IDENTITY Column. In this case you can retreive the newly Generated Identity Value using
 
@@Identity : Is a system function that returns the last-inserted identity value.
OR
Scope_Identity() : Returns the last identity value inserted into an identity column in the same scope. A scope is a module: a stored procedure, trigger, function, or batch.
 
Now if you are using same procedure to ad record in both table then simple access the newly created Identity value using @@Identity or Scope_identity.
Or
If you are using 2 seperate Procedure To Create new Profile and insert record in profiles_plugins then you can use OUTPUT Parameter which will return the newly generated Identity Value to the calling code.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can fetch that id using @@RowCount in sql server. But instead of this u can go for the stored procedure and insert the value in profile table first then get the max(profile_id) and insert this into Profile_plugin table it may be easy way to do that.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 OriginalGriff 448
1 Sergey Alexandrovich Kryukov 425
2 Abhinav S 408
3 sanket saxena 285
4 Tadit Dash 160
0 Sergey Alexandrovich Kryukov 8,482
1 OriginalGriff 4,830
2 Peter Leow 3,794
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 1 Jan 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Use
Layout: fixed | fluid