[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2007-11-14
2
Medium Priority
?
3,337 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 2000 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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Integration Management Part 2
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

834 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