Solved

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

Posted on 2007-11-14
2
3,230 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

839 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