adding parameters

T

tshad

When I normally set up my Sql statements and parameters, I would normally
do:

Dim objCmd as New SqlCommand("AddNewResumeCoverTemplate",objConn)
objCmd.CommandType = CommandType.StoredProcedure
objCmd.parameters.add("@ClientID",SqldbType.VarChar,20).value =
session("ClientID")
objCmd.parameters.add("@Email",SqlDbType.VarChar,45).value =
session("Email")

I am setting up a class where I pass it the parameters and have seen it set
up like:

Dim parameters As SqlParameter () = { _
New SqlParameter("@ClientID",SqlDbType,varChar20), _
New SqlParameter("@Email",SqlDbType.varChar,45)}

parameters(0).value = session("ClientID")
parameters(1).value = session("Email")

Can I combine the 2, similar to the top as something like:

Dim parameters As SqlParameter () = { _
New SqlParameter("@ClientID",SqlDbType,varChar20).value =
Session("ClientID"), _
New SqlParameter("@Email",SqlDbType.varChar,45).value = Session("Email")}

Thanks,

Tom
 
T

tshad

Ben said:

So there is no way to do it in one easy command?

The examples are showing you setting up one parameter and I wanted to set up
a parameter list that I could just put the whole thing in one command where
we define only what we need in the definition of the array:

I tried:

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

But I got an error:

Procedure 'GetUserInfo' expects parameter '@ClientID', which was not
supplied

But if I take out the last argument of each "New SqlParameter' statement and
add the data later it works fine.

****************************************
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
*********************************************

I was hoping to be able to add values in during the "New" statement.

Thanks,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top