开发者

Trim function not removing spaces in name

开发者 https://www.devze.com 2023-02-27 01:25 出处:网络
bool Res = false; DataView DV = new DataView(DT); DV.RowFilter = \"Trim(Originator)=\'\"+OrginatorName.Trim()+\"\'\";
bool Res = false;  

DataView DV = new DataView(DT);
     DV.RowFilter = "Trim(Originator)='"+OrginatorName.Trim()+"'";
     if (DV.Count > 0)
     {
       Res = true;
     }
开发者_开发知识库

I need to get "Originator" from the database and compare it with the OrginatorName to check duplicate values. I need to remove all the white spaces before checking.

For example, the function must consider "John Van" to be the same as "JohnVan". My above code doesn't work. How can I achieve this?


String.Trim() removes whitespace from the beginning and end only, not in the middle. You want to use the String.Replace() method

DV.RowFilter = "Trim(Originator)='"+OrginatorName.Replace(" ", "")+"'";


this line should be

  DV.RowFilter = "Trim(Originator)='"+OrginatorName.Replace(" ","")+"'";


User .Replace instead of .Trim()

0

精彩评论

暂无评论...
验证码 换一张
取 消