Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have DB2 database i connect to it by vb.net all thimg is ok
but when i want to search for an Employee by by name it is not work
here code it work if gname.text is clear show all emplyee

What I have tried:

Dim s As String = "SELECT GEMPNO, GNAME, GTERM  FROM qgpl.testz where gname like '% " & gname.Text & " %' ORDER BY RNAME  "
 dim selectCMD As OdbcCommand = New OdbcCommand(s, MyODBCConnection)
  Dim Adapter As OdbcDataAdapter = New OdbcDataAdapter(selectCMD.CommandText, MyODBCConnection)
            Dim ds As DataSet = New DataSet
            ds.Clear()
            Adapter.Fill(ds, "MyTable")
            Dim Row As DataRow
            Dim listItem1 As New ListViewItem()
            For Each Row In ds.Tables(0).Rows
                If Not IsDBNull(Row.Item(0)) Then
                    listItem1 = New ListViewItem(Row.Item(0).trim.ToString)
                Else
                    listItem1 = New ListViewItem("")
                End If
                If Not IsDBNull(Row.Item(1)) Then
                    listItem1.SubItems.Add(Row.Item(1).ToString.Trim)
                Else
                    listItem1.SubItems.Add("")
                End If
                If Not IsDBNull(Row.Item(2)) Then
                    listItem1.SubItems.Add(Row.Item(2).ToString)
                Else
                    listItem1.SubItems.Add("")
                End If
                ListView1.Items.Add(listItem1)
            Next
        Catch ex As Exception
        End Try
        For i As Integer = 0 To ListView1.Items.Count - 1
            If ListView1.Items(i).SubItems(2).Text <> 0 Then
                ListView1.Items(i).BackColor = Color.LightBlue
            Else
                ListView1.Items(i).BackColor = Color.White
            End If
        Next
        MyODBCConnection.Close()
        MyODBCConnection.Dispose()
Posted
Updated 18-May-17 0:38am
v2
Comments
CHill60 7-May-17 7:05am    
I believe you have to explicitly tell DB2 that the string is UNICODE. Try
Dim s As String = "SELECT GEMPNO, GNAME, GTERM  FROM qgpl.testz where gname like u&@gname ORDER BY RNAME  "
...
selectCMD.Parameters.AddWithValue("@gname", "%" + gname.Text + "%")
...

If that doesn't work then this link might prove useful
Understanding DB2 Universal Database character conversion[^]
zamzam_301 7-May-17 8:23am    
thanks a lot
it does not work
CHill60 7-May-17 8:46am    
Oh well, I tried. I don't have any access to DB2 to play around unfortunately, which is why I only posted this as a comment.
The link might give you some insight though.
Maciej Los 10-May-17 14:40pm    
Sounds like an answer to me.
[no name] 7-May-17 9:10am    
"it not work" is not a description of any kind of a problem.

1 solution

'this code solve my problem

Dim s As String = "SELECT EMPNO, NAME FROM lib.file "
Dim selectCMD As OdbcCommand = New OdbcCommand(s, MyODBCConnection)
'start the Read loop
Dim Adapter As OdbcDataAdapter = New OdbcDataAdapter(selectCMD.CommandText, MyODBCConnection)
Dim ds As DataSet = New DataSet
ds.Clear()
Adapter.SelectCommand = New OdbcCommand("SELECT EMPNO, NAME FROM lib.file where NAME like ? ", MyODBCConnection)
Adapter.SelectCommand.Parameters.Add("@GNAME", Odbc.OdbcType.NVarChar).Value = "%" & gname.Text
Adapter.SelectCommand.ExecuteNonQuery()
Adapter.Fill(ds, "MyTable")
Dim Row As DataRow
Dim listItem1 As New ListViewItem()
For Each Row In ds.Tables(0).Rows
VB

 
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