Global Variable for URL param recommendation

R

Rob

Please recommend best practice for adding a global
variable to an ASP.net class that will take on a
Request.Params("") value from the URL calling the aspx
page to be used throughout in stored procedure calls as a
parameter in datagrids.

Currently, the best I came up with was to add code around
the Web Form Designer code of the Select statement that
defines the variable and sends it as a Parameter to the
stored procedure. However, Visual studio keeps
overwriting this code everytime I use the GUI tools on the
data objects. Using variable in Select Stored Procedure
paramater call in the Value area.

Is there a better/easier way to send the variable in the
GUI "control source" or value for the data adapter select
statement sp call?

Thank you,

Rob

----
'
'SqlSelectCommand1
'
'RW - Attempt to globally define EmployeeID from
URL paramater for stored procedure
If Not (Request.Params("EmployeeID") Is Nothing)
Then
EmployeeID = Int32.Parse(Request.Params
("EmployeeID"))
Else
EmployeeID = "302"
End If
'/RW
Me.SqlSelectCommand1.CommandText
= "[spGetEmpAttach]"
Me.SqlSelectCommand1.CommandType =
System.Data.CommandType.StoredProcedure
Me.SqlSelectCommand1.Connection = Me.SqlConnection1
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@RETURN_VALUE",
System.Data.SqlDbType.Int, 4,
System.Data.ParameterDirection.ReturnValue, False, CType
(0, Byte), CType(0, Byte), "",
System.Data.DataRowVersion.Current, Nothing))
'RW
Me.SqlSelectCommand1.Parameters.Add(New
System.Data.SqlClient.SqlParameter("@EmployeeID",
System.Data.SqlDbType.Int, 4,
System.Data.ParameterDirection.Input, False, CType(0,
Byte), CType(0, Byte), "",
System.Data.DataRowVersion.Current, EmployeeID))
'/RW
 
T

Tian Min Huang

Hi Rob,

I think you could store the variable in a session or application state. So
you could get it throughout the web application.

For an example:
Session["EmployeeID"] = EmployeeID;
Application["EmployeeID "] = EmployeeID;

Please feel free to let me know if you have any problems or concerns.

Have a nice day!

Regards,

HuangTM
Microsoft Online Partner Support
MCSE/MCSD

Get Secure! ¨C www.microsoft.com/security
This posting is provided ¡°as is¡± with no warranties and confers no rights.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top