473,473 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Using multiple parameters for SqlConnection

Hello,

I have a stored procedure that requires 3 parameters. How do you add
multiple parameters for a SqlConnection?

Thanks, Steven
Public strConn = "Data Source=MyServer;Initial Catalog=MyDatabase;User
Id=MyUser;Password=MyPwd;"
Dim cnnSearch As SqlConnection = New SqlConnection(strConn)
Dim cmdRegion As SqlCommand = New SqlCommand("SalesByCategory", cnnSearch)
cmdRegion.CommandType = CommandType.StoredProcedure

Dim myParm As SqlParameter = cmdRegion.Parameters.Add("@CategoryName",
SqlDbType.VarChar, 15)
myParm.Value = "NorthAmerica"

cnnSearch.Open()

Dim myReader As SqlDataReader = cmdRegion.ExecuteReader()
Nov 18 '05 #1
3 1643
It looks like you already know how to add parameters, so what's the problem?
Just do what you did to add 1 parameter, but do it 3 times.

"sck10" <sc***@online.nospam> wrote in message
news:uo**************@TK2MSFTNGP15.phx.gbl...
Hello,

I have a stored procedure that requires 3 parameters. How do you add
multiple parameters for a SqlConnection?

Thanks, Steven
Public strConn = "Data Source=MyServer;Initial Catalog=MyDatabase;User
Id=MyUser;Password=MyPwd;"
Dim cnnSearch As SqlConnection = New SqlConnection(strConn)
Dim cmdRegion As SqlCommand = New SqlCommand("SalesByCategory", cnnSearch)
cmdRegion.CommandType = CommandType.StoredProcedure

Dim myParm As SqlParameter = cmdRegion.Parameters.Add("@CategoryName",
SqlDbType.VarChar, 15)
myParm.Value = "NorthAmerica"

cnnSearch.Open()

Dim myReader As SqlDataReader = cmdRegion.ExecuteReader()

Nov 18 '05 #2
Thanks for Marina's quick response!

Hi Steve,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know how to add 3
parameters to a SqlCommand object. If there is any misunderstanding, please
feel free to let me know.

Just like Marina mentioned, seems that you know how to add 1 parameter. You
can do it 3 times to add your 3 parameters, since SqlCommand.Parameters is
a collection, which can hold all the parameters required for the stored
procedure. The return value for the Add method is the reference to the
newly added parameter.

For more information, please check the following link:

http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemDataSqlClientSqlCommandClassParametersT opic.asp

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 18 '05 #3
Hi Steve,

I'd like to know if this issue has been resolved yet. Is there anything
that I can help. I'm still monitoring on it. If you have any questions,
please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 18 '05 #4

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

Similar topics

0
by: Nashat Wanly | last post by:
HOW TO: Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET View products that this article applies to. This article was previously published under Q310070 For a Microsoft...
6
by: simon | last post by:
Always when I need data reader in my programs, I simply have functions, which creates it for me: Dim rdr As SqlDataReader dim sql as string sql="myStoredProcedure" rdr =...
3
by: Renato Vieira | last post by:
I get the error 'Procedure 'spBO_HeadlineCreate' expects parameter '@imageid', which was not supplied' when i call the procedure with the @imageid=null, but id the @imageid as a diff. value no...
2
by: Mike Hutton | last post by:
I have a rather odd problem. I have a SP which uses temp. tables along the way, and then returns a table of results: CREATE PROCEDURE dbo.usp_myproc( @pNameList VARCHAR(6000) ) AS
1
by: Tim::.. | last post by:
I am trying to create a multiple update for a datagrid! At the moment I have the following sub which could probably be written better but I'm new to ASP.NET and trying to get this to work first. ...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
8
by: Andrew Robinson | last post by:
Are these two equivalent? Is one better than the other? I tend to go with #1 but started wondering.... Thanks, 1: using (SqlConnection cn = new SqlConnection(DataConnection)) using...
6
by: thomson | last post by:
Hi All, i do hae a solution in which i do have mulitple projects including Web Projects,, Depending on the functionality it gets redirected to different web projects and it is working fine, ...
5
by: satyabhaskar | last post by:
hi all, In my web page i have created radio buttons dynamically on to the page .....following is my code string Course, Semester, Section; int rowsCount; string con =...
0
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...
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...
1
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...
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...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.