Topic
No replies
mdruk
mdruk
1 Post
ACCEPTED ANSWER

Pinned topic SQL0802 Data conversion or data mapping error

‏2012-06-29T18:35:48Z |
I have a visual basic program in visual studio 2010 where the user can type in a portion of customers name and get a list of customers who have similiar names and then the user selects the specific customer. The search is performed within iSeries version 7. The customer name is stored in the iSeries as following: SMITH, JOHN Q.

If the user enters SMITH, it works, if the user enters just SMITH without the comma i receive the SQL0802 error. I want the user to be able to widen the search by being able to just enter the first few letters of last name but the comma stored in iSeries is not being handled properly. In the following code, i assume that the "thisCommand.Parameters("@uname").Value = txtName.Text & "%"" is where the problem is, i just do not know how to escape the comma properly. Any suggestions? The entire code is below:

Private Sub txtName_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtName.Leave
If txtName.Text "" Then
If txtName.Text name1 Then

Dim thisConnection As New iDB2Connection("DataSource=sub; Naming=System; LibraryList=QS36F, *USRLIBL")
Dim thisCommand As New iDB2Command("SELECT ""UBA.MF""., ""UBA.VR""., FUELADJ.* FROM ""UBA.MF"" INNER JOIN ""UBA.VR"" ON ""UBA.MF"".UACCT = ""UBA.VR"".UACCT LEFT OUTER JOIN FUELADJ ON ""UBA.MF"".BILLDT = FUELADJ.BILLDT WHERE (UNAME LIKE @uname)", thisConnection)
Dim thisReader As iDB2DataReader
Try
thisConnection.Open()
thisCommand.DeriveParameters()
thisCommand.Parameters("@uname").Value = txtName.Text & "%"
thisReader = thisCommand.ExecuteReader()
Dim dt As New DataTable("UBA.MF")
dt.Load(thisReader)
NameSearch.dgv2.DataSource = dt
thisReader.Close()
thisCommand.Dispose()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
thisConnection.Close()
End Try

NameSearch.TopMost = True
NameSearch.Show()
HistoryToolStripMenuItem.Visible = True

End If
End If

End Sub