Reputation: 1
I am trying to search through an SQL table of records to find and extract those records whose fields match my criteria.
The field name is ID and it is a 13 digit code, stored as Integer in the SQL itself. I need to search each record by the first six digits of the ID field (not primary key field).
Below is the code:
Dim results As DataSet.DataRow() = DataSet.DataTable.Select("LEFT(ID,6) = 123456")
Here is the error message:
The expression contains undefined function call LEFT().
I suspect the problem is with the LEFT function in the SQL filter - because if I run .Select on, say, "ID = some-ID-value", the corresponding record is returned properly.
Perhaps SQL functions are not recognized when the .Select() is used? Or maybe I should use CAST?
Upvotes: 0
Views: 199
Reputation: 3408
An alternative is to create a DataView with your existing DataTable; apply filter and get filtered rows into another data table. This is safe code.
DataView dataView = new DataView(DataSet.DataTable);
dataView.RowFilter = "ID LIKE '123456%'";
var filtredData = dataView.ToTable();
Upvotes: 1