im having a problem with the Select() method in my datatable.
If i want to search in my DataTable for multiple patterns (search function)
For string Columns the ‘Like’ works
Select(String.Format("Requester like '%{0}%'", tb_RequesterSearch.Text))
but i also need to check for Numeric patterns in my Numeric column
if i try something like
For Each drOrder As DataRow In dsDatabase.Tables("ProjektImport").Select(String.Format("PONumber like '%{0}%'", convert.toDouble(tb_POSearch.Text)))
'Do something
Next
i always get the exception, that ‘Like’ is not supportet for Numeric columns.
Is there an equivalent function or a way to cast my column as string (only in the select)?
Thanks in advance
LIKE Expressions don’t work on numeric columns. You could add an additional
varcharcolumn to your DataTable viaselect-clause(before it is filled) or use following LINQ way:Don’t confuse the ADO.NET LIKE Expression with the VB.NET’s LIKE-Operator, that i’ve used here to keep it simple and working. I could also have been used
String.Containsor aRegularExpressionto achieve the same, it’s a trade-off between performance and flexibility.