Enable Case Sensitive when using DataTable.select

让人想犯罪 __ 提交于 2019-12-22 12:52:34

问题


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 ?


回答1:


Set DataTable.CaseSensitive to True.

Assuming Myfunction() returns a DataTable:

string TRUCK = "trUck";
var dt = MyWebControl.Myfunction();
dt.CaseSensitive = True;
dt.Select("TransportationMode = '" + TRUCK + "'");



回答2:


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.



来源:https://stackoverflow.com/questions/13292771/enable-case-sensitive-when-using-datatable-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!