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;Connecti on 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").Va lue() = txtName.Text
cmd.Parameters("@Address") .Value() = txtAddress.Text
cmd.Parameters("@city").Va lue() = txtCity.Text
cmd.Parameters("@state").V alue() = txtState.Text
cmd.Parameters("@Zip").Val ue() = 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?
Dim cn As iDB2Connection = New iDB2Connection("User ID=yeah;Password=yeah;Data
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,
'Open connection
cn.Open()
cmd.Parameters("@Name").Va
cmd.Parameters("@Address")
cmd.Parameters("@city").Va
cmd.Parameters("@state").V
cmd.Parameters("@Zip").Val
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 ()?