473,831 Members | 2,420 Online
Bytes | Software Development & Data Engineering Community
+ 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",Sqldb Type.VarChar,20 ), _
New SqlParameter("@ UserName",SqlDb Type.VarChar,20 ), _
New SqlParameter("@ Password",SqlDb Type.VarChar,20 ) }

parameters(0).v alue = session("Client ID")
parameters(1).v alue = UserName.text
parameters(2).v alue = Password.Text

dbReader = myDbObject.RunP rocedure("GetUs erInfo", 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",Sqldb Type.VarChar,20 ) ,
New SqlParameter("@ Password",SqlDb Type.VarChar,20 ) )

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

Dim objCmd as New SqlCommand(Comm andText,objConn )
....
objCmd.Paramete rs.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 2877
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**********@f tsolutions.com> wrote in message
news:eR******** ******@TK2MSFTN GP14.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",Sqldb Type.VarChar,20 ), _
New SqlParameter("@ UserName",SqlDb Type.VarChar,20 ), _
New SqlParameter("@ Password",SqlDb Type.VarChar,20 ) }

parameters(0).v alue = session("Client ID")
parameters(1).v alue = UserName.text
parameters(2).v alue = Password.Text

dbReader = myDbObject.RunP rocedure("GetUs erInfo", 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",Sqldb Type.VarChar,20 ) ,
New SqlParameter("@ Password",SqlDb Type.VarChar,20 ) )

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

Dim objCmd as New SqlCommand(Comm andText,objConn )
...
objCmd.Paramete rs.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
"CodeMeiste r" <jw********@cod emeister.net> wrote in message
news:OR******** ******@TK2MSFTN GP09.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 BuildQueryComma nd( _
ByVal storedProcName As String, _
ByVal parameters As IDataParameter( )) _
As SqlCommand

Dim command As New SqlCommand(stor edProcName, myConnection)
command.Command Type = CommandType.Sto redProcedure

Dim parameter As SqlParameter
For Each parameter In parameters
command.Paramet ers.Add(paramet er)
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**********@f tsolutions.com> wrote in message
news:eR******** ******@TK2MSFTN GP14.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",Sqldb Type.VarChar,20 ), _
New SqlParameter("@ UserName",SqlDb Type.VarChar,20 ), _
New SqlParameter("@ Password",SqlDb Type.VarChar,20 ) }

parameters(0).v alue = session("Client ID")
parameters(1).v alue = UserName.text
parameters(2).v alue = Password.Text

dbReader = myDbObject.RunP rocedure("GetUs erInfo", 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",Sqldb Type.VarChar,20 ) ,
New SqlParameter("@ Password",SqlDb Type.VarChar,20 ) )

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

Dim objCmd as New SqlCommand(Comm andText,objConn )
...
objCmd.Paramete rs.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
30144
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) { $_SESSION = array(); } ?> <form enctype="multipart/form-data" name="company_info" method="post" action="add_pic.php">
6
8191
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 to get reset. Is there any way to reset that ? When do the buffers for the dynamic SQL get updated reset?
4
6295
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 * From SomeTable Where index = " + nSomeNumber.ToString(); SqlCommand ....etc
1
14398
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 button on my ASP.NET web page, and have an HTML reset button click clear 1) all validator text display and 2) validation summary display. Problem was clearing them and yet still leaving them working and visible if the user immediately began...
1
4635
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 sql parameters on the fly if it is possible as I have a long form with a load of textboxes that I want to input the values of into a database! Thanks for any help!
5
1481
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 coded.. My problem is on the same page i have a CHECKBOXLIST which is DAtabinded and the DataValuefield i binded it to increments 1,2,3... which is p_id(I'm doing that becos i need to pass those values) My table looks like this :- p_id ...
2
5232
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 the id of my form is "form1". This gives the error "Object doesn't support this property or method". Please advise.
11
7432
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 is not reset to '0' when i push the reset button. If I simply change the node from "<input type="hidden" id='IsChanged' value='0'>" to "<input type="text" id='IsChanged' value='0'>" Everything is working as expected (the value is reset to '0'...
16
2088
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
9794
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...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10780
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10497
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7753
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
5623
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
5788
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4420
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
3968
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.