473,406 Members | 2,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Cannot refer to ADO SQLParameters by name

Hi All,
I am trying to move my experience with VB6 and ADO over to VB.NET. I am
having difficulty with assigning values to SQL parameters. In classic ADO a
value could be assigned to a parameter by referring to it with the index as
the parameter name in quotes. Here is some code to illustrate the problem.

Dim parameters As SqlParameter() = { _
New SqlParameter("@DocRef", SqlDbType.VarChar, 30), _
New SqlParameter("@EdiDocID", SqlDbType.Int, 4) _
}
parameters(0).Value = DocRef
parameters(1).Value = EdiDocID

That code works fine. But when I try:

parameters("@DocRef").Value = DocRef
parameters("@EdiDocID" ).Value = EdiDocID

I get a type conversion error. This doesn't present much of a problem with
only 2 parameters, but I will be working with a stored procedure that will
take up to 200 parameters. That will become a maintenance nightmare if just
1 parameter is added or removed in the list. It will throw the whole numeric
index sequence off. Can somebody please suggest how I might circumvent this
problem?
Thank you all in advance.

Nov 21 '05 #1
2 1296
Try this...

Dim cmd As New SqlClient.SqlCommand()

cmd.Parameters.Add("@DocRef", SqlDbType.VarChar, 30).Value = DocRef
cmd.Parameters.Add("@EdiDocID", SqlDbType.VarChar, 30).Value = EdiDocID
"John Kotuby" <jk*****@snet.net> wrote in message
news:Oa**************@TK2MSFTNGP09.phx.gbl...
Hi All,
I am trying to move my experience with VB6 and ADO over to VB.NET. I am
having difficulty with assigning values to SQL parameters. In classic ADO a value could be assigned to a parameter by referring to it with the index as the parameter name in quotes. Here is some code to illustrate the problem.

Dim parameters As SqlParameter() = { _
New SqlParameter("@DocRef", SqlDbType.VarChar, 30), _
New SqlParameter("@EdiDocID", SqlDbType.Int, 4) _
}
parameters(0).Value = DocRef
parameters(1).Value = EdiDocID

That code works fine. But when I try:

parameters("@DocRef").Value = DocRef
parameters("@EdiDocID" ).Value = EdiDocID

I get a type conversion error. This doesn't present much of a problem with only 2 parameters, but I will be working with a stored procedure that will
take up to 200 parameters. That will become a maintenance nightmare if just 1 parameter is added or removed in the list. It will throw the whole numeric index sequence off. Can somebody please suggest how I might circumvent this problem?
Thank you all in advance.

Nov 21 '05 #2
Thanks Shawn...

I will try that syntax. Looks like it will be easier to manage.

"Shawn" <sh**********@ccci.org> wrote in message
news:un**************@TK2MSFTNGP12.phx.gbl...
Try this...

Dim cmd As New SqlClient.SqlCommand()

cmd.Parameters.Add("@DocRef", SqlDbType.VarChar, 30).Value = DocRef
cmd.Parameters.Add("@EdiDocID", SqlDbType.VarChar, 30).Value = EdiDocID
"John Kotuby" <jk*****@snet.net> wrote in message
news:Oa**************@TK2MSFTNGP09.phx.gbl...
Hi All,
I am trying to move my experience with VB6 and ADO over to VB.NET. I am
having difficulty with assigning values to SQL parameters. In classic ADO

a
value could be assigned to a parameter by referring to it with the index

as
the parameter name in quotes. Here is some code to illustrate the
problem.

Dim parameters As SqlParameter() = { _
New SqlParameter("@DocRef", SqlDbType.VarChar, 30), _
New SqlParameter("@EdiDocID", SqlDbType.Int, 4) _
}
parameters(0).Value = DocRef
parameters(1).Value = EdiDocID

That code works fine. But when I try:

parameters("@DocRef").Value = DocRef
parameters("@EdiDocID" ).Value = EdiDocID

I get a type conversion error. This doesn't present much of a problem

with
only 2 parameters, but I will be working with a stored procedure that
will
take up to 200 parameters. That will become a maintenance nightmare if

just
1 parameter is added or removed in the list. It will throw the whole

numeric
index sequence off. Can somebody please suggest how I might circumvent

this
problem?
Thank you all in advance.


Nov 21 '05 #3

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

Similar topics

4
by: bettina | last post by:
Hello, My domain: www.coaster.ch My database: coasters User: bettina In the programm I wrote: <?php $db_server = "www.coaster.ch";
4
by: WM Chung | last post by:
Hi all, I meet a problem in building my .Net Solution and I would like to seek help. After I have added a dll to reference in one of my project in my solution, when I re-build the solution, I...
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: 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...
2
by: tshad | last post by:
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: ***********************************************...
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...
0
by: Larry Lard | last post by:
This came out of a thread explaining to "BK" about error BC42025 ("Access of shared member through an instance; qualifying expression will not be evaluated"); Frans Clasener then came up with...
6
by: RAM | last post by:
Hello, Could you help me please to solve the prblem with connecting to SQL Server from .NET development environment? I have the following error: "An error has occured while establishing a...
1
by: teenagelcruise | last post by:
hi, i have a problem with my code which is i cannot update and addnew data into the database but i can delete the data.plz give me an idea.this is my code that i wrote. <html> <head> <meta...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.