473,803 Members | 3,857 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.VarCh ar, 30), _
New SqlParameter("@ EdiDocID", SqlDbType.Int, 4) _
}
parameters(0).V alue = DocRef
parameters(1).V alue = EdiDocID

That code works fine. But when I try:

parameters("@Do cRef").Value = DocRef
parameters("@Ed iDocID" ).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 1322
Try this...

Dim cmd As New SqlClient.SqlCo mmand()

cmd.Parameters. Add("@DocRef", SqlDbType.VarCh ar, 30).Value = DocRef
cmd.Parameters. Add("@EdiDocID" , SqlDbType.VarCh ar, 30).Value = EdiDocID
"John Kotuby" <jk*****@snet.n et> wrote in message
news:Oa******** ******@TK2MSFTN GP09.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.VarCh ar, 30), _
New SqlParameter("@ EdiDocID", SqlDbType.Int, 4) _
}
parameters(0).V alue = DocRef
parameters(1).V alue = EdiDocID

That code works fine. But when I try:

parameters("@Do cRef").Value = DocRef
parameters("@Ed iDocID" ).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**********@c cci.org> wrote in message
news:un******** ******@TK2MSFTN GP12.phx.gbl...
Try this...

Dim cmd As New SqlClient.SqlCo mmand()

cmd.Parameters. Add("@DocRef", SqlDbType.VarCh ar, 30).Value = DocRef
cmd.Parameters. Add("@EdiDocID" , SqlDbType.VarCh ar, 30).Value = EdiDocID
"John Kotuby" <jk*****@snet.n et> wrote in message
news:Oa******** ******@TK2MSFTN GP09.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.VarCh ar, 30), _
New SqlParameter("@ EdiDocID", SqlDbType.Int, 4) _
}
parameters(0).V alue = DocRef
parameters(1).V alue = EdiDocID

That code works fine. But when I try:

parameters("@Do cRef").Value = DocRef
parameters("@Ed iDocID" ).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
5363
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
6145
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 meet the following error : ------ Rebuild All started: Project: OIDCOMMON, Configuration: Debug .NET ------ Preparing resources...
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
4634
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!
2
2877
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: *********************************************** Dim myDbObject as new DbObject() Dim DBReader As SqlDataReader Dim parameters As SqlParameter () = { _ New SqlParameter("@ClientID",SqldbType.VarChar,20), _ New SqlParameter("@UserName",SqlDbType.VarChar,20), _
5
1480
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 ...
0
1604
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 another similar problem, which I believe shows up a bug (well, a problem) in VB2005. As many will know, VB2005 saw the reintroduction of the 'default instance' of Form classes, allowing one to write code such as Form1.Show
6
1976
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 connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default setting SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could nott open a connection...
1
2469
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 http-equiv="Content-Type" content="text/html; charset=windows-1252"> <title>Order Record</title> <meta name="Microsoft Border" content="tlb, default"> </head>
0
9700
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...
1
10292
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10068
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9121
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7603
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
6841
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4275
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
3796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.