Storing return value of a Stored Proc in a Session

Discussion in 'ASP .Net' started by raghav, Nov 2, 2006.

  1. raghav

    raghav Guest

    Hi all
    I am having a SP which is returning a value......Now I have to store
    that value

    in session...I saw some examples in msdn lib ---->
    string Name=string.Empty;
    Session["Raghav"]=Name.ToString();


    But in my case return value is ID ...and it has not been declared in C#

    code as Name is declared in Above exapmle...bec i am not inserting that

    ID from front end....
    So what will be the C# code to store value returned from SP in a
    session?I posted this query in other group also but no good
    response....Looking for further responses...
    --Raghav
     
    raghav, Nov 2, 2006
    #1
    1. Advertising

  2. what exactly are you trying to achieve?? can you post some sample
    code...???
    raghav wrote:
    > Hi all
    > I am having a SP which is returning a value......Now I have to store
    > that value
    >
    > in session...I saw some examples in msdn lib ---->
    > string Name=string.Empty;
    > Session["Raghav"]=Name.ToString();
    >
    >
    > But in my case return value is ID ...and it has not been declared in C#
    >
    > code as Name is declared in Above exapmle...bec i am not inserting that
    >
    > ID from front end....
    > So what will be the C# code to store value returned from SP in a
    > session?I posted this query in other group also but no good
    > response....Looking for further responses...
    > --Raghav
     
    donet programmer, Nov 2, 2006
    #2
    1. Advertising

  3. raghav

    raghav Guest

    Hi
    See, I want to store a value returned from Stored Proc in a session
    using C#...Yes I will post code------

    ALTER PROCEDURE Applicant1
    @FirstName char(20),
    @MiddleName char(20),
    @LastName char(20),
    @DoB Datetime,
    @Gender Char(10),
    @Email varchar(20),
    @Mobile numeric(12,0),
    @ResumePath varchar(MAX),
    @Address varchar(MAX),
    @City char(30),
    @State int,
    @Country int,
    @Pin numeric(10,0),
    @phone numeric(15,0),
    @Addressp varchar(MAX),
    @Cityp char(30),
    @Statep int,
    @Countryp int,
    @Pinp numeric(10,0),
    @phonep numeric(15,0),
    @Hobbies varchar(250),
    @Interests varchar(250),
    @Achievements varchar(250),
    @IsPermanentAddress bit,
    @ApplicantID int output

    AS
    SET NOCOUNT ON

    IF @IsPermanentAddress = 0

    begin

    INSERT INTO
    Applicant(FirstName,MiddleName,LastName,Gender,Email,Mobile,ResumePath,DoB)
    Values(@FirstName,@MiddleName,@LastName,@Gender,@Email,@Mobile,@ResumePath,@DoB)

    select @ApplicantID = @@Identity

    insert into
    ContactDetails(Address,City,StateID,CountryID,Pin,Phone,IsPermanentAddress,ApplicantID)
    values(@Address,@City,@State,@Country,@Pin,@Phone,@IsPermanentAddress,@ApplicantID)

    insert into PersonalDetails(Hobbies,Interests,Achievements,ApplicantID)
    values(@Hobbies,@Interests,@Achievements,@ApplicantID)


    end

    ELSE

    INSERT INTO
    Applicant(FirstName,MiddleName,LastName,DoB,Gender,Email,Mobile,ResumePath)
    Values(@FirstName,@MiddleName,@LastName,@DoB,@Gender,@Email,@Mobile,@ResumePath)

    select @ApplicantID = @@Identity

    insert into
    ContactDetails(Address,City,StateID,CountryID,Pin,Phone,IsPermanentAddress,ApplicantID)
    values(@Address,@City,@State,@Country,@Pin,@Phone,@IsPermanentAddress,@ApplicantID)

    insert into
    ContactDetails(Address,City,StateID,CountryID,Pin,Phone,IsPermanentAddress,ApplicantID)
    values(@Addressp,@Cityp,@Statep,@Countryp,@Pinp,@Phonep,@IsPermanentAddress,@ApplicantID)

    insert into PersonalDetails(Hobbies,Interests,Achievements,ApplicantID)
    values(@Hobbies,@Interests,@Achievements,@ApplicantID)
    RETURN @ApplicantID
    --------------------------------------------------------------------------------------------------------------------------------
    This SP is returning ApplicantID.I have to store this ID in a session,
    Then I will pass that value in other SP.So just I want to know that How
    I can store this value in session..ApplicantID is not inserted from
    front end, It just exists in Database....
    Hope u understood what I exactly want...
    Regards
    Raghav..

    donet programmer wrote:
    > what exactly are you trying to achieve?? can you post some sample
    > code...???
    > raghav wrote:
    > > Hi all
    > > I am having a SP which is returning a value......Now I have to store
    > > that value
    > >
    > > in session...I saw some examples in msdn lib ---->
    > > string Name=string.Empty;
    > > Session["Raghav"]=Name.ToString();
    > >
    > >
    > > But in my case return value is ID ...and it has not been declared in C#
    > >
    > > code as Name is declared in Above exapmle...bec i am not inserting that
    > >
    > > ID from front end....
    > > So what will be the C# code to store value returned from SP in a
    > > session?I posted this query in other group also but no good
    > > response....Looking for further responses...
    > > --Raghav
     
    raghav, Nov 2, 2006
    #3
  4. hope this provides some help ..
    http://aspnet.4guysfromrolla.com/articles/062905-1.aspx

    raghav wrote:
    > Hi
    > See, I want to store a value returned from Stored Proc in a session
    > using C#...Yes I will post code------
    >
    > ALTER PROCEDURE Applicant1
    > @FirstName char(20),
    > @MiddleName char(20),
    > @LastName char(20),
    > @DoB Datetime,
    > @Gender Char(10),
    > @Email varchar(20),
    > @Mobile numeric(12,0),
    > @ResumePath varchar(MAX),
    > @Address varchar(MAX),
    > @City char(30),
    > @State int,
    > @Country int,
    > @Pin numeric(10,0),
    > @phone numeric(15,0),
    > @Addressp varchar(MAX),
    > @Cityp char(30),
    > @Statep int,
    > @Countryp int,
    > @Pinp numeric(10,0),
    > @phonep numeric(15,0),
    > @Hobbies varchar(250),
    > @Interests varchar(250),
    > @Achievements varchar(250),
    > @IsPermanentAddress bit,
    > @ApplicantID int output
    >
    > AS
    > SET NOCOUNT ON
    >
    > IF @IsPermanentAddress = 0
    >
    > begin
    >
    > INSERT INTO
    > Applicant(FirstName,MiddleName,LastName,Gender,Email,Mobile,ResumePath,DoB)
    > Values(@FirstName,@MiddleName,@LastName,@Gender,@Email,@Mobile,@ResumePath,@DoB)
    >
    > select @ApplicantID = @@Identity
    >
    > insert into
    > ContactDetails(Address,City,StateID,CountryID,Pin,Phone,IsPermanentAddress,ApplicantID)
    > values(@Address,@City,@State,@Country,@Pin,@Phone,@IsPermanentAddress,@ApplicantID)
    >
    > insert into PersonalDetails(Hobbies,Interests,Achievements,ApplicantID)
    > values(@Hobbies,@Interests,@Achievements,@ApplicantID)
    >
    >
    > end
    >
    > ELSE
    >
    > INSERT INTO
    > Applicant(FirstName,MiddleName,LastName,DoB,Gender,Email,Mobile,ResumePath)
    > Values(@FirstName,@MiddleName,@LastName,@DoB,@Gender,@Email,@Mobile,@ResumePath)
    >
    > select @ApplicantID = @@Identity
    >
    > insert into
    > ContactDetails(Address,City,StateID,CountryID,Pin,Phone,IsPermanentAddress,ApplicantID)
    > values(@Address,@City,@State,@Country,@Pin,@Phone,@IsPermanentAddress,@ApplicantID)
    >
    > insert into
    > ContactDetails(Address,City,StateID,CountryID,Pin,Phone,IsPermanentAddress,ApplicantID)
    > values(@Addressp,@Cityp,@Statep,@Countryp,@Pinp,@Phonep,@IsPermanentAddress,@ApplicantID)
    >
    > insert into PersonalDetails(Hobbies,Interests,Achievements,ApplicantID)
    > values(@Hobbies,@Interests,@Achievements,@ApplicantID)
    > RETURN @ApplicantID
    > --------------------------------------------------------------------------------------------------------------------------------
    > This SP is returning ApplicantID.I have to store this ID in a session,
    > Then I will pass that value in other SP.So just I want to know that How
    > I can store this value in session..ApplicantID is not inserted from
    > front end, It just exists in Database....
    > Hope u understood what I exactly want...
    > Regards
    > Raghav..
    >
    > donet programmer wrote:
    > > what exactly are you trying to achieve?? can you post some sample
    > > code...???
    > > raghav wrote:
    > > > Hi all
    > > > I am having a SP which is returning a value......Now I have to store
    > > > that value
    > > >
    > > > in session...I saw some examples in msdn lib ---->
    > > > string Name=string.Empty;
    > > > Session["Raghav"]=Name.ToString();
    > > >
    > > >
    > > > But in my case return value is ID ...and it has not been declared in C#
    > > >
    > > > code as Name is declared in Above exapmle...bec i am not inserting that
    > > >
    > > > ID from front end....
    > > > So what will be the C# code to store value returned from SP in a
    > > > session?I posted this query in other group also but no good
    > > > response....Looking for further responses...
    > > > --Raghav
     
    donet programmer, Nov 2, 2006
    #4
  5. raghav

    raghav Guest

    Hi
    This link is giving information about returning value from a stored
    procedure. This was not my question. I want to know that how I can
    store that value returned from SP in a session in page behind using C#
    2005.
    --Raghav
    donet programmer wrote:
    > hope this provides some help ..
    > http://aspnet.4guysfromrolla.com/articles/062905-1.aspx
    >
    > raghav wrote:
    > > Hi
    > > See, I want to store a value returned from Stored Proc in a session
    > > using C#...Yes I will post code------
    > >
    > > ALTER PROCEDURE Applicant1
    > > @FirstName char(20),
    > > @MiddleName char(20),
    > > @LastName char(20),
    > > @DoB Datetime,
    > > @Gender Char(10),
    > > @Email varchar(20),
    > > @Mobile numeric(12,0),
    > > @ResumePath varchar(MAX),
    > > @Address varchar(MAX),
    > > @City char(30),
    > > @State int,
    > > @Country int,
    > > @Pin numeric(10,0),
    > > @phone numeric(15,0),
    > > @Addressp varchar(MAX),
    > > @Cityp char(30),
    > > @Statep int,
    > > @Countryp int,
    > > @Pinp numeric(10,0),
    > > @phonep numeric(15,0),
    > > @Hobbies varchar(250),
    > > @Interests varchar(250),
    > > @Achievements varchar(250),
    > > @IsPermanentAddress bit,
    > > @ApplicantID int output
    > >
    > > AS
    > > SET NOCOUNT ON
    > >
    > > IF @IsPermanentAddress = 0
    > >
    > > begin
    > >
    > > INSERT INTO
    > > Applicant(FirstName,MiddleName,LastName,Gender,Email,Mobile,ResumePath,DoB)
    > > Values(@FirstName,@MiddleName,@LastName,@Gender,@Email,@Mobile,@ResumePath,@DoB)
    > >
    > > select @ApplicantID = @@Identity
    > >
    > > insert into
    > > ContactDetails(Address,City,StateID,CountryID,Pin,Phone,IsPermanentAddress,ApplicantID)
    > > values(@Address,@City,@State,@Country,@Pin,@Phone,@IsPermanentAddress,@ApplicantID)
    > >
    > > insert into PersonalDetails(Hobbies,Interests,Achievements,ApplicantID)
    > > values(@Hobbies,@Interests,@Achievements,@ApplicantID)
    > >
    > >
    > > end
    > >
    > > ELSE
    > >
    > > INSERT INTO
    > > Applicant(FirstName,MiddleName,LastName,DoB,Gender,Email,Mobile,ResumePath)
    > > Values(@FirstName,@MiddleName,@LastName,@DoB,@Gender,@Email,@Mobile,@ResumePath)
    > >
    > > select @ApplicantID = @@Identity
    > >
    > > insert into
    > > ContactDetails(Address,City,StateID,CountryID,Pin,Phone,IsPermanentAddress,ApplicantID)
    > > values(@Address,@City,@State,@Country,@Pin,@Phone,@IsPermanentAddress,@ApplicantID)
    > >
    > > insert into
    > > ContactDetails(Address,City,StateID,CountryID,Pin,Phone,IsPermanentAddress,ApplicantID)
    > > values(@Addressp,@Cityp,@Statep,@Countryp,@Pinp,@Phonep,@IsPermanentAddress,@ApplicantID)
    > >
    > > insert into PersonalDetails(Hobbies,Interests,Achievements,ApplicantID)
    > > values(@Hobbies,@Interests,@Achievements,@ApplicantID)
    > > RETURN @ApplicantID
    > > --------------------------------------------------------------------------------------------------------------------------------
    > > This SP is returning ApplicantID.I have to store this ID in a session,
    > > Then I will pass that value in other SP.So just I want to know that How
    > > I can store this value in session..ApplicantID is not inserted from
    > > front end, It just exists in Database....
    > > Hope u understood what I exactly want...
    > > Regards
    > > Raghav..
    > >
    > > donet programmer wrote:
    > > > what exactly are you trying to achieve?? can you post some sample
    > > > code...???
    > > > raghav wrote:
    > > > > Hi all
    > > > > I am having a SP which is returning a value......Now I have to store
    > > > > that value
    > > > >
    > > > > in session...I saw some examples in msdn lib ---->
    > > > > string Name=string.Empty;
    > > > > Session["Raghav"]=Name.ToString();
    > > > >
    > > > >
    > > > > But in my case return value is ID ...and it has not been declared in C#
    > > > >
    > > > > code as Name is declared in Above exapmle...bec i am not inserting that
    > > > >
    > > > > ID from front end....
    > > > > So what will be the C# code to store value returned from SP in a
    > > > > session?I posted this query in other group also but no good
    > > > > response....Looking for further responses...
    > > > > --Raghav
     
    raghav, Nov 3, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. smen
    Replies:
    3
    Views:
    11,393
    Scott Allen
    Jan 9, 2004
  2. hansiman
    Replies:
    0
    Views:
    508
    hansiman
    Feb 5, 2005
  3. David Lozzi
    Replies:
    3
    Views:
    1,996
    David Lozzi
    Jun 1, 2005
  4. Learner
    Replies:
    4
    Views:
    10,430
    bhawin13
    Dec 22, 2005
  5. Scott
    Replies:
    11
    Views:
    307
    Scott
    Apr 12, 2004
Loading...

Share This Page