Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable Case Sensitive when using DataTable.select

My database includes only

Truck

however my below select statment returns the rows with 'Truck'

MyWebControl.Myfunction().Select("TransportationMode = '" + TRUCK + "'");

How can I make this select statement case sensitive ?

like image 639
HOY Avatar asked Dec 01 '22 20:12

HOY


2 Answers

Set DataTable.CaseSensitive to True.

Assuming Myfunction() returns a DataTable:

string TRUCK = "trUck";
var dt = MyWebControl.Myfunction();
dt.CaseSensitive = True;
dt.Select("TransportationMode = '" + TRUCK + "'");
like image 115
lc. Avatar answered Dec 04 '22 09:12

lc.


If you're at least on .NET 3.5 you could use linq which is much more powerful and readable than the DataTable.Select syntax.

string mode = "Truck";
var rows = table.AsEnumerable()
                .Where(r = > r.Field<string>("TransportationMode") == mode);

It's case sensitive by default.

like image 28
Tim Schmelter Avatar answered Dec 04 '22 10:12

Tim Schmelter