Create Session ID after my Save Button

Create Session id after my save button click.
I'm trying to simply create a session id after my save button event. After i save my data, i'd like to have my session be the primary key of Table2 which is titled POMONTHID, so it's not visible in any of the code behind or stored procedure.

My original SQL Stored Procedure to insert my data is
ALTER PROCEDURE [dbo].[ReturnIDwithOutput]
	@Suppint Varchar(50),
	@VendorCode Varchar(10),
	@classgroupAllocID Varchar(10),
	@Season Varchar(4),
	@quarter Varchar(50),
	@Month Varchar(50),
	@DateAllocated Date,
	@StyleCreated Varchar(5),
	@Category VARCHAR(50),
	INSERT INTO [dbo].[Table1] (Suppint,VendorCode,classgroupAllocID,Season,[quarter],CreateDate)
	VALUES (@Suppint,@VendorCode,@classgroupAllocID,@Season,@quarter,GETDATE());
	INSERT INTO [dbo].[Table2](POID,[Month],DateAllocated,StyleCreated,EDIT,Category,CreateDate) VALUES (@POID,@Month,@DateAllocated,@StyleCreated,@EDIT,@Category,GetDATE());


Open in new window

the code behind to call the stored procedure from ASP objects is here:
Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSave.Click

        Dim strConnString As String = ConfigurationManager.ConnectionStrings("connstring").ConnectionString
            Dim con As New SqlConnection(strConnString)
            Dim cmd As New SqlCommand()

            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "[dbo].[ReturnIDwithOutput]"
            cmd.Parameters.Add("@Suppint", SqlDbType.VarChar).Value = ddlSupplier.Text.Trim()
            cmd.Parameters.Add("@VendorCode", SqlDbType.VarChar).Value = tbsuppliercode.Text.Trim()

            cmd.Parameters.Add("@classgroupAllocID", SqlDbType.VarChar).Value = If(ddlclass.Text = String.Empty, DBNull.Value, CType(ddlclass.Text, String))           
            cmd.Parameters.Add("@Season", SqlDbType.VarChar).Value = If(ddlSeason.Text = String.Empty, DBNull.Value, CType(ddlSeason.Text, String))          
            cmd.Parameters.Add("@quarter", SqlDbType.VarChar).Value = If(ddlquarter.Text = String.Empty, DBNull.Value, CType(ddlquarter.Text, String))            
            cmd.Parameters.Add("@Month", SqlDbType.VarChar).Value = If(ddlMonth.Text = String.Empty, DBNull.Value, CType(ddlMonth.Text, String))            
            cmd.Parameters.Add("@DateAllocated", SqlDbType.Date).Value = If(DateAllocated.Text = String.Empty, DBNull.Value, CType(DateAllocated.Text, Date))            
            cmd.Parameters.Add("@StyleCreated", SqlDbType.VarChar).Value = If(ddlStyleCreated.Text = String.Empty, DBNull.Value, CType(ddlStyleCreated.Text, String))            
            cmd.Parameters.Add("@EDIT", SqlDbType.Bit).Value = If(ChkEdit.Checked, 1, 0)
            cmd.Parameters.Add("@Category", SqlDbType.VarChar).Value = If(ddlCategory.Text = String.Empty, DBNull.Value, CType(ddlCategory.Text, String))            
            cmd.Parameters.Add("@POID", SqlDbType.Int).Direction = ParameterDirection.Output

            cmd.Connection = con
                Dim poid As String = cmd.Parameters("@POID").Value.ToString()

                lblPOID.Text = poid

            Catch ex As Exception
                Throw ex
            End Try
End Sub

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul MacDonaldDirector, Information SystemsCommented:
The user's session is created when the user connects to the web server.  You can't create it yourself.

That said, you can capture the extant session ID (HttpSessionState.SessionID) and use that.   I can't advocate using it as THE primary key in your table because that's something SQL Server should be in charge of, but you may very well be able to get away with it.
Southern_GentlemanAuthor Commented:
Thansk Paul,

so i updated the web.config, i changed it to the recommended regenerateExpiredSessionID="true".  Do you have an example of either changing the Global.asax Session_Start or a way to add it to the save button on the click event?
Paul MacDonaldDirector, Information SystemsCommented:
"Do you have an example of either changing the Global.asax Session_Start or a way to add it to the save button on the click event?"
This doesn't generate a Session ID either, just revives an old one.  Again, the Session ID already exists, you just have to tap into it.  HttpSessionState.SessionID will do that for you.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Southern_GentlemanAuthor Commented:
OK, thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.