Link to home
Start Free TrialLog in
Avatar of bergertime
bergertime

asked on

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

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?
ASKER CERTIFIED SOLUTION
Avatar of Ashish Patel
Ashish Patel
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of WaldenL
WaldenL

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 ()?