473,732 Members | 2,146 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.P age

'RW - Global Employee ID to be used for URL EmployeeID
Parameter.
Public EmployeeID

#Region " Web Form Designer Generated Code "
....
'
'SqlSelectComma nd1
'
'RW - Attempt to globally define EmployeeID from
URL paramater for stored procedure
If Not (Request.Params ("EmployeeID ") Is Nothing)
Then
EmployeeID = Int32.Parse(Req uest.Params
("EmployeeID "))
Else
EmployeeID = "302"
End If
'/RW
Me.SqlSelectCom mand1.CommandTe xt
= "[spGetEmpAttach]"
Me.SqlSelectCom mand1.CommandTy pe =
System.Data.Com mandType.Stored Procedure
Me.SqlSelectCom mand1.Connectio n = Me.SqlConnectio n1
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@RETURN_V ALUE",
System.Data.Sql DbType.Int, 4,
System.Data.Par ameterDirection .ReturnValue, False, CType
(0, Byte), CType(0, Byte), "",
System.Data.Dat aRowVersion.Cur rent, Nothing))
'RW
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.Sql Client.SqlParam eter("@Employee ID",
System.Data.Sql DbType.Int, 4,
System.Data.Par ameterDirection .Input, False, CType(0,
Byte), CType(0, Byte), "",
System.Data.Dat aRowVersion.Cur rent, EmployeeID))
'/RW
Nov 17 '05 #1
1 3682
>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.EventArg s) Handles MyBase.Load
'RW - Session state for insert function, then
fills the dataset with stored procedure
GetURL()
If IsPostBack Then
DsAttachmentDtl s1 = CType(Session
("SessionAttac hmentDtls"), dsAttachmentDtl s)
Else
SqlDataAdapter1 .Fill(DsAttachm entDtls1)
Session("Sessio nAttachmentDtls ") =
DsAttachmentDt ls1
DataGrid1.DataB ind()
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.SqlSelectCom mand1.Parameter s.Item
("@EmployeeID" ) = CType(EmployeeI D,
System.Data.Sq lClient.SqlPara meter)
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.P age

'RW - Global Employee ID to be used for URL

EmployeeID
Parameter.
Public EmployeeID

#Region " Web Form Designer Generated Code "
....
'
'SqlSelectComma nd1
'
'RW - Attempt to globally define EmployeeID from
URL paramater for stored procedure
If Not (Request.Params ("EmployeeID ") Is Nothing)
Then
EmployeeID = Int32.Parse(Req uest.Params
("EmployeeID" ))
Else
EmployeeID = "302"
End If
'/RW
Me.SqlSelectCom mand1.CommandTe xt
= "[spGetEmpAttach]"
Me.SqlSelectCom mand1.CommandTy pe =
System.Data.C ommandType.Stor edProcedure
Me.SqlSelectCom mand1.Connectio n =

Me.SqlConnecti on1
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.S qlClient.SqlPar ameter("@RETURN _VALUE",
System.Data.S qlDbType.Int, 4,
System.Data.P arameterDirecti on.ReturnValue, False, CType
(0, Byte), CType(0, Byte), "",
System.Data.D ataRowVersion.C urrent, Nothing))
'RW
Me.SqlSelectCom mand1.Parameter s.Add(New
System.Data.S qlClient.SqlPar ameter("@Employ eeID",
System.Data.S qlDbType.Int, 4,
System.Data.P arameterDirecti on.Input, False, CType(0,
Byte), CType(0, Byte), "",
System.Data.D ataRowVersion.C urrent, EmployeeID))
'/RW
.


Hi Rob,

Regarding the casting error; I assume you're getting the error on this line:
Me.SqlSelectCom mand1.Parameter s.Item("@Employ eeID") = CType(EmployeeI D, System.Data.Sql Client.SqlParam eter)
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.SqlSelectCom mand1.Parameter s.Item("@Employ eeID") = CType(EmployeeI D, System.Data.Sql Client.SqlParam eter.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
1937
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 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,...
6
4758
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 (say) of a list of numbers, or a concatination of a set of strings (again, example), but if I wanted to, for example, keep that value available for another template later on to use, I can't see how I could do that. Let me give a better example. I...
0
1324
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 include other XSL files. like
1
2002
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 include other XSL files. like
5
2051
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 = "param.txt";' is declared globally. a) What is the use of declaring a global variable static? b) Why in this thread they had use "const" the two times? c) When mentionting as const, the variable we declared remains
5
33078
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 Form1 (main form) and Form2, there is parameter in form2 I have to called from form1. So please would you tell me how? Any way thanks
5
1436
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 variable between pages. any ideas?
12
2228
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
2065
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
8944
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9234
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6733
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6030
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.