Solved

vb.net SQL statement parameters using IBM.Data.DB2.iSeries to AS400

Posted on 2007-11-14
2
3,207 Views
Last Modified: 2013-11-26
Here is my code:

 Dim cn As iDB2Connection = New iDB2Connection("User ID=yeah;Password=yeah;Data Source=10.1.1.999;Connection Timeout = 0")
        Dim cmd As iDB2Command
        Dim sqlstring As String        

                sqlstring = "insert into weslib2.wp1401p (saacct, sanam1, sanam2, saadd1, sacity) values (@Name, @Address, @City, @State, @Zip)"

        cmd = New iDB2Command(sqlstring, cn)
        'cmd.Prepare()

        Dim da As New iDB2DataAdapter(sqlstring, cn)
     
        'Open connection
        cn.Open()
        cmd.Parameters("@Name").Value() = txtName.Text
        cmd.Parameters("@Address").Value() = txtAddress.Text
        cmd.Parameters("@city").Value() = txtCity.Text
        cmd.Parameters("@state").Value() = txtState.Text
        cmd.Parameters("@Zip").Value() = txtZip.Text



        cmd.ExecuteNonQuery()

        cn.Close()
        TextBox1.Text = sqlstring

When I run this I get error:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Any ideas on it?
0
Comment
Question by:bergertime
2 Comments
 
LVL 23

Accepted Solution

by:
Ashish Patel earned 500 total points
ID: 20282917
Try this.
Dim cn As iDB2Connection = New iDB2Connection("User ID=yeah;Password=yeah;Data Source=10.1.1.999;Connection Timeout = 0")
        Dim cmd As iDB2Command
        Dim sqlstring As String        

                sqlstring = "insert into weslib2.wp1401p (saacct, sanam1, sanam2, saadd1, sacity) values (@Name, @Address, @City, @State, @Zip)"

        cmd = New iDB2Command(sqlstring, cn)

        Dim da As New iDB2DataAdapter(sqlstring, cn)
With cmd.Parameters
            .Add(New SqlParameter("@Name", txtName.Text))
            .Add(New SqlParameter("@Address", txtAddress.Text))
            .Add(New SqlParameter("@City", txtCity.Text))
            .Add(New SqlParameter("@State", txtState.Text))
            .Add(New SqlParameter("@Zip", txtZip.Text))
        End With
        'Open connection
        cn.Open()
        cmd.ExecuteNonQuery()
        cn.Close()
        TextBox1.Text = sqlstring
0
 
LVL 3

Expert Comment

by:WaldenL
ID: 20283285
First, you've commented out the prepare, so the parameter collection will be empty. Second, I don't think you can have () at the end of  .Value, it's a property not a method. Actually I'm suprised that complies, as you can't assigned to a method, maybe VB ignores the ()?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now