Optimize Store Procedure routine

I

inadsad

Dear Group,
I have a store procedure with 12 input parameter and 2 output
parameters I'm wondering what's the best way to simplify the
following routine. I'd like to eliminate extra line of codes, do I
need to define input direction for each input parameter? I'm using
VS2005. I'd appreciate any useful feedback.

Thank You
Ian Nads
-------------------------------------------
Sqlparam = SqlComm.Parameters.Add(New
SqlClient.SqlParameter("@CustID", SqlDbType.Int))
Sqlparam.Direction = ParameterDirection.Input
Sqlparam.Value = CustomerID

Sqlparam = SqlComm.Parameters.Add(New
SqlClient.SqlParameter("@inAddr1", SqlDbType.VarChar))
Sqlparam.Direction = ParameterDirection.Input
Sqlparam.Value = Address1

Sqlparam = SqlComm.Parameters.Add(New
SqlClient.SqlParameter("@inAddr2", SqlDbType.VarChar))
Sqlparam.Direction = ParameterDirection.Input
Sqlparam.Value = Address2

...

Sqlparam = SqlComm.Parameters.Add(New
SqlClient.SqlParameter("@ID", SqlDbType.int))
Sqlparam.Direction = ParameterDirection.Output

Sqlparam = SqlComm.Parameters.Add(New
SqlClient.SqlParameter("@ID2", SqlDbType.int))
Sqlparam.Direction = ParameterDirection.Output

' excecute store procedure
SqlComm.ExecuteNonQuery()
ID = SqlComm.Parameters(13).Value
ID2 = SqlComm.Parameters(14).Value

-------------------------------------------
 
L

Lloyd Sheen

Dear Group,
I have a store procedure with 12 input parameter and 2 output
parameters I'm wondering what's the best way to simplify the
following routine. I'd like to eliminate extra line of codes, do I
need to define input direction for each input parameter? I'm using
VS2005. I'd appreciate any useful feedback.

Thank You
Ian Nads
-------------------------------------------
Sqlparam = SqlComm.Parameters.Add(New
SqlClient.SqlParameter("@CustID", SqlDbType.Int))
Sqlparam.Direction = ParameterDirection.Input
Sqlparam.Value = CustomerID

Sqlparam = SqlComm.Parameters.Add(New
SqlClient.SqlParameter("@inAddr1", SqlDbType.VarChar))
Sqlparam.Direction = ParameterDirection.Input
Sqlparam.Value = Address1

Sqlparam = SqlComm.Parameters.Add(New
SqlClient.SqlParameter("@inAddr2", SqlDbType.VarChar))
Sqlparam.Direction = ParameterDirection.Input
Sqlparam.Value = Address2

...

Sqlparam = SqlComm.Parameters.Add(New
SqlClient.SqlParameter("@ID", SqlDbType.int))
Sqlparam.Direction = ParameterDirection.Output

Sqlparam = SqlComm.Parameters.Add(New
SqlClient.SqlParameter("@ID2", SqlDbType.int))
Sqlparam.Direction = ParameterDirection.Output

' excecute store procedure
SqlComm.ExecuteNonQuery()
ID = SqlComm.Parameters(13).Value
ID2 = SqlComm.Parameters(14).Value

-------------------------------------------

If you check in the Object explorer you will see Input is the default for a
SqlParameter so you will not need that line unless you are dealing with a
value other than Input

LS
 

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

Top