Click here to Skip to main content
14,297,726 members
Rate this:
Please Sign up or sign in to 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
Updated 12-Oct-17 7:38am

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Something like this:
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(", ")

cmd.CommandText = sql.ToString()

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

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

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100