Ask a Question related to ASP.NET General, Design and Development.
-
Rob Wire #1
Public/Global Variable recommendation for URL Param and SQL
Please let me know the preferred way to do the following.
Accept a Variable in the calling page's URL of an ID. Set
that variable to be global scope of the class so that it
can be used throughout the functions from Page Load.
Would like to send the ID variable as a SQL parameter to
stored procedures for Select, Update, and Insert.
What I have done so far to get around it is declare it in
the SQL Select statements of the Web form code, then
create a new parameter for the stored procedure, then edit
the value to have the variable. However, Visual Studio
keeps overwriting this code with the GUI tools, just
looking at the properties.
Please advise. Thank you, Rob
----
Public Class WebForm1
Inherits System.Web.UI.Page
'RW - Global Employee ID to be used for URL EmployeeID
Parameter.
Public EmployeeID
#Region " Web Form Designer Generated Code "
....
'
'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
Rob Wire Guest
-
global variable
I have made a site where I need to be able to include a file containing an array of settings in many pages. This array needs to have global scope... -
global variable problem
I want a counter progCounter to count the number of times that the frame is entered. Ultimately, I would like it to count the number of times that... -
Global variable and tempo
set the member of sprite 10 to member("loopValSel") or sprite(10).member=member("loopValSel") hth -- ---------------- -- Ned... -
Global Variable declaration
For some reason this wont compile, it says that i need to declare the variable before using it on prepareMovie global sm204 -
Help Please: 'Warning 5001 global variable "iF_timer" already defined in global scope
Hi there, I have just started to get this error: 'Warning 5001 global variable "iF_timer" already defined in global scope The variable name... -
Rick Rainey[MSFT] #2
RE: Public/Global Variable recommendation for URL Param and SQL
>I've started trying to define the following, but get
Hi Rob,>a "Specified cast is not valid." error on the SQL
>parameter. Am I on the right track? Thank you in
>advance, Rob.
>---
> Private Sub Page_Load(ByVal sender As System.Object,
>ByVal e As System.EventArgs) Handles MyBase.Load
> 'RW - Session state for insert function, then
>fills the dataset with stored procedure
> GetURL()
> If IsPostBack Then
> DsAttachmentDtls1 = CType(Session
>("SessionAttachmentDtls"), dsAttachmentDtls)
> Else
> SqlDataAdapter1.Fill(DsAttachmentDtls1)
> Session("SessionAttachmentDtls") =
>DsAttachmentDtls1
> DataGrid1.DataBind()
> End If
> End Sub
> 'RW - Global Employee ID to be used for URL EmployeeID
>Parameter.
> Public EmployeeID
> Public Sub GetURL()
> 'RW - Attempt to globally define EmployeeID from
>URL paramater for stored procedure
> If Not (Request.Params("EmployeeID") Is Nothing)
>Then
> EmployeeID = Request.Params("EmployeeID")
> Else
> EmployeeID = "302"
> End If
> '/RW
> Me.SqlSelectCommand1.Parameters.Item
>("@EmployeeID") = CType(EmployeeID,
>System.Data.SqlClient.SqlParameter)
> End Sub
>>following.>>-----Original Message-----
>>Please let me know the preferred way to do the>Set>>Accept a Variable in the calling page's URL of an ID.>edit>>that variable to be global scope of the class so that it
>>can be used throughout the functions from Page Load.
>>Would like to send the ID variable as a SQL parameter to
>>stored procedures for Select, Update, and Insert.
>>
>>What I have done so far to get around it is declare it in
>>the SQL Select statements of the Web form code, then
>>create a new parameter for the stored procedure, then>EmployeeID>>the value to have the variable. However, Visual Studio
>>keeps overwriting this code with the GUI tools, just
>>looking at the properties.
>>
>>Please advise. Thank you, Rob
>>----
>>Public Class WebForm1
>> Inherits System.Web.UI.Page
>>
>> 'RW - Global Employee ID to be used for URL>Me.SqlConnection1>>Parameter.
>> Public EmployeeID
>>
>>#Region " Web Form Designer Generated Code "
>>....
>> '
>> '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.SqlSelectCommand1.Parameters.Add(New
>>System.Data.SqlClient.SqlParameter("@RETURN_VALU E",
>>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
>>
>>
>>.
>>
Regarding the casting error; I assume you're getting the error on this line:
In your CType function call, you need to specify a particular SqlDBType. Assuming EmployeeID is going to be an integer, then you will need to change you> Me.SqlSelectCommand1.Parameters.Item("@EmployeeID" ) = CType(EmployeeID, System.Data.SqlClient.SqlParameter)
code as follows:
> Me.SqlSelectCommand1.Parameters.Item("@EmployeeID" ) = CType(EmployeeID, System.Data.SqlClient.SqlParameter.SqlDbType.Int)
Thanks,
Rick[MSFT]
--
This posting is provided "AS IS" with no warranties, and confers no rights. Use of included script samples are subject to the terms specified at
[url]http://www.microsoft.com/info/cpyright.htm[/url]
Note: For the benefit of the community-at-large, all responses to this message are best directed to the newsgroup/thread from which they originated.
Rick Rainey[MSFT] Guest



Reply With Quote

