473,320 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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
Nov 17 '05 #1
1 3645
>I've started trying to define the following, but get
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
-----Original Message-----
Please let me know the preferred way to do thefollowing.
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_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
.


Hi Rob,

Regarding the casting error; I assume you're getting the error on this line:
Me.SqlSelectCommand1.Parameters.Item("@EmployeeID" ) = CType(EmployeeID, System.Data.SqlClient.SqlParameter)
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
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
http://www.microsoft.com/info/cpyright.htm

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.

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Rob | last post by:
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...
6
by: Loopy | last post by:
I'm learning XML and XSL at the moment, but I still can't get my head around the concept of non-updatable variables. I know we can use recursion to cycle through a data structure and get the sum...
0
by: Eshrath Khan | last post by:
Hi all, I have a .Net program which access transforms a XML using an XSL stylesheet. The .net program calls Stylesheet main.xsl file. The main.xls contains only <xsl:include> elements to...
1
by: Eshrath Khan | last post by:
Hi all, I have a .Net program which access transforms a XML using an XSL stylesheet. The .net program calls Stylesheet main.xsl file. The main.xls contains only <xsl:include> elements to...
5
by: sworna vidhya | last post by:
Hai, When viewing threads of comp.lang.c, I came across with 'static const char * const resultFileName = "param.txt";' . Here in this thread, 'static const char * const resultFileName =...
5
by: MMSJED | last post by:
I am beginner in using C#, actually I am trying to move from VB6 to C# I need very small help in programming problem my be you will laugh when you get it That simply I have to form let’s say...
5
by: Steve Mauldin | last post by:
Having weird things happening with my code. Two users on at the same time and data entered by one user is added into another users global variable. global variable data being stored in session...
12
by: a | last post by:
def fn(): for i in range(l) global count count= .... how do i declare count to be global if it is an array subsequently i should access or define count as an array error:
18
by: Bruce | last post by:
When I do this: <input id="someName" type="text"> <script type="text/javascript"> alert(someName.nodeName); </script> Both IE6 and Firefox alert("INPUT"). Why isn't "someName" undefined?
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.