无法对System.Boolean和System.String执行'Like'操作。 [英] Cannot perform 'Like' operation on System.Boolean and System.String.

查看:235
本文介绍了无法对System.Boolean和System.String执行'Like'操作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用列表框。如果我在教科书中输入文字。它在列表框中的文件管理器。当我恢复错误时:无法对System.Boolean和System.String执行''Like''操作。以下是我的代码

 私人  Sub  txtitems_TextChanged( ByVal  sender  As  System。 Object  ByVal  e  As  System.EventArgs) Handles  txtitems.TextChanged 
尝试

Dim strSortColumn 作为 字符串
strSortColumn = ListGroup.Sorted
ListGroup.Sorted = True
DirectCast (ListGroup.DataSource,DataTable).DefaultView.RowFilter = & strSortColumn& like'%& txtitems.Text.Trim()& %'
' ListGroup.SelectedItem.ToString()。包含(txtitems.Text)
Catch ex < span class =code-keyword> As 异常
MainForm.ErrorMsg.StatusBarMsg( 您无法对此列进行排序或搜索!!排序其他列!!,Bx_UI_COM_ErrorMsg.ErrorComponent.MessageType.bx_Error)
结束 尝试
结束 Sub

解决方案

为布尔列添加条件...如下所示...

 私有  Sub  txtitems_TextChanged( ByVal  sender  As  System。 Object  ByVal  e  As  System.EventArgs)句柄 txtitems.TextChanged 
尝试
Dim strSortColumn 作为 String
strSortColumn = ListGroup.Sorted
ListGroup.Sorted = True
Dim FilterCondition =
if DirectCast (ListGroup.DataSource,DataTable).Columns [strSortColumn] .DataType.Tostring()。ToLower()。Contains( bool然后
FilterCondition = & strSortColumn& = 1 ' 0表示错误1表示真实
else
FilterCondition = & strSortColumn& like'%& txtitems.Text.Trim()& %'
end if
DirectCast (ListGroup.DataSource,DataTable).DefaultView.RowFilter = FilterCondition
' ListGroup.SelectedItem.ToString()。包含(txtitems.Text)
< span class =code-keyword> Catch ex As 异常
MainForm.ErrorMsg.StatusBarMsg( 您无法对此列进行排序或搜索!!排序其他列!!,Bx_UI_COM_ErrorMsg.ErrorComponent.MessageType.bx_Error)
< span class =code-keyword>结束 尝试
结束 Sub



快乐编码!

:)

hai i am using list box. if i enter the text in textbook . it filer in the list box . at the time i am reviving the error:Cannot perform ''Like'' operation on System.Boolean and System.String. below is my code

Private Sub txtitems_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtitems.TextChanged
       Try

           Dim strSortColumn As String
           strSortColumn = ListGroup.Sorted
           ListGroup.Sorted = True
           DirectCast(ListGroup.DataSource, DataTable).DefaultView.RowFilter = "" & strSortColumn & " like '%" & txtitems.Text.Trim() & "%' "
           'ListGroup.SelectedItem.ToString().Contains(txtitems.Text)
       Catch ex As Exception
           MainForm.ErrorMsg.StatusBarMsg("You Cannot Sort or Search on this column!! Sort other column!!", Bx_UI_COM_ErrorMsg.ErrorComponent.MessageType.bx_Error)
       End Try
   End Sub

解决方案

put condition for boolean column... like below...

 Private Sub txtitems_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtitems.TextChanged
        Try
            Dim strSortColumn As String
            strSortColumn = ListGroup.Sorted
            ListGroup.Sorted = True
Dim FilterCondition = ""
if  DirectCast(ListGroup.DataSource, DataTable).Columns[strSortColumn].DataType.Tostring().ToLower().Contains("bool") then
    FilterCondition = "" & strSortColumn & "=1" '0 for false 1 for true
else
    FilterCondition = "" & strSortColumn & " like '%" & txtitems.Text.Trim() & "%' "
end if
            DirectCast(ListGroup.DataSource, DataTable).DefaultView.RowFilter = FilterCondition 
            'ListGroup.SelectedItem.ToString().Contains(txtitems.Text)
        Catch ex As Exception
            MainForm.ErrorMsg.StatusBarMsg("You Cannot Sort or Search on this column!! Sort other column!!", Bx_UI_COM_ErrorMsg.ErrorComponent.MessageType.bx_Error)
        End Try
    End Sub


Happy Coding!
:)


这篇关于无法对System.Boolean和System.String执行'Like'操作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆