Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I was able to connect to
iSeries Access ODBC Driver
using ASP.Net.
Simple where clause and select is working but when I have encountered the WHERE IN CLAUSE it throws back error.
My code is like this below:

Dim sql as string ="Select * from table where column in (?)"

cmd.Parameters.Add("", Odbc.OdbcType.Char).Value = txt_Param.Text

and my textbox will have value of 'a','b','c'


I am getting this error:

ERROR [22018] [IBM][iSeries Access ODBC Driver]Column 1: CWB0111 - A buffer passed to a system call is too small to hold return data ERROR [22001] [IBM][iSeries Access ODBC Driver]Column 1: Character data right truncation.


I figured out that parameters is one is to one. how will i have many parameters in odbc?

What I have tried:

Tried changing string and adding commas but it is not working
Posted
Updated 12-Oct-17 7:38am

1 solution

Something like this:
VB.NET
Dim sql As New StringBuilder("SELECT * FROM table WHERE column IN (")

Dim parts As String() = txt_Param.Text.Split(","c)
For i As Integer = 0 To parts.Length - 1
    cmd.Parameters.Add("", Odbc.OdbcType.Char).Value = parts(i)
    If i <> 0 Then sql.Append(", ")
    sql.Append("?"c)
Next

sql.Append(")"c)
cmd.CommandText = sql.ToString()

You might want to look at Dapper[^], which makes this sort of query much easier.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900