473,473 Members | 1,730 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Reset SqlParameters

I have an SqlParameter array that I want to reuse after I have used it.

For example, I have the following code that calls my generic db routines:
***********************************************
Dim myDbObject as new DbObject()
Dim DBReader As SqlDataReader

Dim parameters As SqlParameter () = { _
New SqlParameter("@ClientID",SqldbType.VarChar,20), _
New SqlParameter("@UserName",SqlDbType.VarChar,20), _
New SqlParameter("@Password",SqlDbType.VarChar,20) }

parameters(0).value = session("ClientID")
parameters(1).value = UserName.text
parameters(2).value = Password.Text

dbReader = myDbObject.RunProcedure("GetUserInfo", parameters)
************************************************** ****

I now want to use the same parameters but this time I have only @ClientID
and @Password:

Dim parameters As SqlParameter () = { _
New SqlParameter("@ClientID",SqldbType.VarChar,20) ,
New SqlParameter("@Password",SqlDbType.VarChar,20) )

Now in my old way I would clear the parameters of the SqlCommand object like
so:

Dim objCmd as New SqlCommand(CommandText,objConn)
....
objCmd.Parameters.Clear()

How do I do that with my SqlParameter array?

Also, I pass my parameters to my routine as "ByVal parameters As
IDataParameter()". If I have no parameters, how would I set up my Dim to
show there are no parameters (I still need to send a parameter array).

Thanks,

Tom
Nov 19 '05 #1
2 2863
A couple things here. I'm assuming you are using a new IDbCommand object for
each database call. Whether you can reuse your exiting parameters or not
depends on how you are attaching them to the command.If you are cloning the
parameters and attaching the copy you can reuse the parameters. If you are
attaching them directly to the command object you will not be able to reuse
them. Parameters can only be attached to a single command. You would have to
create a new parameter array for the second call.

I would highly recommend looking at the Data Access Aplication Block in the
Microsoft Application Blocks. You might be able to use the block as is and
not have to "recreate the wheel" or use it as a starting point if you need
to extend it. Here's the link to the v2.0 block:
http://www.microsoft.com/downloads/d...displaylang=en

IHTH

Jon
"tshad" <ts**********@ftsolutions.com> wrote in message
news:eR**************@TK2MSFTNGP14.phx.gbl...
I have an SqlParameter array that I want to reuse after I have used it.

For example, I have the following code that calls my generic db routines:
***********************************************
Dim myDbObject as new DbObject()
Dim DBReader As SqlDataReader

Dim parameters As SqlParameter () = { _
New SqlParameter("@ClientID",SqldbType.VarChar,20), _
New SqlParameter("@UserName",SqlDbType.VarChar,20), _
New SqlParameter("@Password",SqlDbType.VarChar,20) }

parameters(0).value = session("ClientID")
parameters(1).value = UserName.text
parameters(2).value = Password.Text

dbReader = myDbObject.RunProcedure("GetUserInfo", parameters)
************************************************** ****

I now want to use the same parameters but this time I have only @ClientID
and @Password:

Dim parameters As SqlParameter () = { _
New SqlParameter("@ClientID",SqldbType.VarChar,20) ,
New SqlParameter("@Password",SqlDbType.VarChar,20) )

Now in my old way I would clear the parameters of the SqlCommand object
like so:

Dim objCmd as New SqlCommand(CommandText,objConn)
...
objCmd.Parameters.Clear()

How do I do that with my SqlParameter array?

Also, I pass my parameters to my routine as "ByVal parameters As
IDataParameter()". If I have no parameters, how would I set up my Dim to
show there are no parameters (I still need to send a parameter array).

Thanks,

Tom

Nov 19 '05 #2
"CodeMeister" <jw********@codemeister.net> wrote in message
news:OR**************@TK2MSFTNGP09.phx.gbl...
A couple things here. I'm assuming you are using a new IDbCommand object
for each database call. Whether you can reuse your exiting parameters or
not depends on how you are attaching them to the command.If you are cloning
the parameters and attaching the copy you can reuse the parameters. If you
are attaching them directly to the command object you will not be able to
reuse them. Parameters can only be attached to a single command. You would
have to create a new parameter array for the second call.
I am just sending the Parameter array to my procedure (which calls another
procedure) to build the SqlCommand object. Here is procedure:

************************************************** *****************************
Private Function BuildQueryCommand( _
ByVal storedProcName As String, _
ByVal parameters As IDataParameter()) _
As SqlCommand

Dim command As New SqlCommand(storedProcName, myConnection)
command.CommandType = CommandType.StoredProcedure

Dim parameter As SqlParameter
For Each parameter In parameters
command.Parameters.Add(parameter)
Next

Return command

End Function
************************************************** *******************************

I pass the parameter list to this procedure which then goes through the list
and adds it to the new SqlCommand object one by one.

So I can keep using the parameter list. But I need to find out how to add,
change or delete the SqlParameters from the array.

Thanks,

Tom
I would highly recommend looking at the Data Access Aplication Block in
the Microsoft Application Blocks. You might be able to use the block as is
and not have to "recreate the wheel" or use it as a starting point if you
need to extend it. Here's the link to the v2.0 block:
http://www.microsoft.com/downloads/d...displaylang=en

IHTH

Jon
"tshad" <ts**********@ftsolutions.com> wrote in message
news:eR**************@TK2MSFTNGP14.phx.gbl...
I have an SqlParameter array that I want to reuse after I have used it.

For example, I have the following code that calls my generic db routines:
***********************************************
Dim myDbObject as new DbObject()
Dim DBReader As SqlDataReader

Dim parameters As SqlParameter () = { _
New SqlParameter("@ClientID",SqldbType.VarChar,20), _
New SqlParameter("@UserName",SqlDbType.VarChar,20), _
New SqlParameter("@Password",SqlDbType.VarChar,20) }

parameters(0).value = session("ClientID")
parameters(1).value = UserName.text
parameters(2).value = Password.Text

dbReader = myDbObject.RunProcedure("GetUserInfo", parameters)
************************************************** ****

I now want to use the same parameters but this time I have only @ClientID
and @Password:

Dim parameters As SqlParameter () = { _
New SqlParameter("@ClientID",SqldbType.VarChar,20) ,
New SqlParameter("@Password",SqlDbType.VarChar,20) )

Now in my old way I would clear the parameters of the SqlCommand object
like so:

Dim objCmd as New SqlCommand(CommandText,objConn)
...
objCmd.Parameters.Clear()

How do I do that with my SqlParameter array?

Also, I pass my parameters to my routine as "ByVal parameters As
IDataParameter()". If I have no parameters, how would I set up my Dim to
show there are no parameters (I still need to send a parameter array).

Thanks,

Tom


Nov 19 '05 #3

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

Similar topics

9
by: Ken | last post by:
How can I reset the initial form variables that are set with session statements when clicking on a button? I tried this but the function was not called: <?PHP function reset_form($none) {...
6
by: Ramachandran Subramanian | last post by:
I have a question regarding the db2 reset monitor. When I issue the command and do a get snapshot I see most of the counters are reset . How ever the Dynamic SQL snapshot section doesnt seem...
4
by: Gav | last post by:
Hi All, Can somebody tell me the advantage of using SqlParameters over simple putting the paratmeters in the sql string: ie Getsomething(int nSomeNumber) { string sSqlStatement= "Select *...
1
by: NancyASAP | last post by:
Thought I'd share this since it took me a long time to get it working. Thanks to a bunch of contributers in Google Groups who shared javascript, etc. The question was: How can I put a reset...
1
by: Tim::.. | last post by:
Can someone please tell me how I build an array with all my SQLParameters! I want to do something like the example shown below... (" I know it doesn't work!") I would like to generate all the...
5
by: Patrick.O.Ige | last post by:
I have a parameter below and i'm passing the value via Store procedure Cmd.Parameters.Add(New SqlParameter("@ProductID", SqlDbType.Int, 1)).Value = 104 But as you can see the value "104" is hard...
2
by: Roger Withnell | last post by:
I need to reset a form to its original value using onclick rather than the Reset button. So, I have: <input type="button" name="reset" id="reset" value="Reset" onclick="form1.reset();"> where...
11
by: newbie | last post by:
i have a form in which a hidden field (initial value as '0', and my javascript set it to '1' when an event is trigged). In the same form, i have a reset field. But I realized that the hidden field...
16
by: Giovanni D'Ascola | last post by:
Hi. I noticed that <input type="reset"actually don't enable checkbutton which are checked by default after they have been disabled by javascript. It's a bug?
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
1
muto222
php
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.