I am creating a form that will filter datagridview while typing in a textbox. I came through this error and I would like to know why is occur.
Dim dt As DataTable = Ds_Pos.Employees
Dim dv As New DataView(dt)
'findcrit is declared as string public and it contain a field name stored in combo
Dim _RowFilter As String = ""
Dim _FieldType = dt.Columns(findcrit).DataType.ToString
Select Case _FieldType
Case "System.Int32" or "System.Int64"
_RowFilter = "convert(" & findcrit & ", 'System.String') like '" & Me.TextBox10.Text & "'"
Case "System.Double"
_RowFilter = "convert(" & findcrit & ", 'System.String') like '" & Me.TextBox10.Text & "'"
Case "System.String"
_RowFilter = findcrit & " like '" & TextBox10.Text & "*'"
End Select
dv.RowFilter = _RowFilter
EmployeesDataGridView.DataSource = dv
I got error in line 8
Conversion from string "System.Int32" to type 'Long' is not valid.
Now If i change the above Select Case to
Select Case _FieldType
Case "System.Int32"
_RowFilter = "convert(" & findcrit & ", 'System.String') like '" & Me.TextBox10.Text & "'"
Case "System.Int64"
_RowFilter = "convert(" & findcrit & ", 'System.String') like '" & Me.TextBox10.Text & "'"
Case "System.Double"
_RowFilter = "convert(" & findcrit & ", 'System.String') like '" & Me.TextBox10.Text & "'"
Case "System.String"
_RowFilter = findcrit & " like '" & TextBox10.Text & "*'"
End Select
It works fine
I know the Select Case
can accept the or
but why not in the above code?