Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DataTable.Select()行值为空白_C#_Datatable - Fatal编程技术网

C# DataTable.Select()行值为空白

C# DataTable.Select()行值为空白,c#,datatable,C#,Datatable,如何解析、比较数据表中有空格的值 我试着 string str= "A B C"; DataRow[] foundRows; foundRows = datatable1.Select("a= '" + str + "'"); 在我的数据表column'a'中,数据为 A B C A B D ACD AB C 没有空间它可以工作,但是空间它不能工作。请解决我的问题 提前谢谢 这里的abc和abc都是不同的

如何解析、比较数据表中有空格的值

我试着

 string str= "A B C";

 DataRow[] foundRows;
 foundRows = datatable1.Select("a= '" + str + "'"); 
在我的数据表column'a'中,数据为

 A B C        
 A B D   
 ACD                  
       AB C
没有空间它可以工作,但是空间它不能工作。请解决我的问题 提前谢谢


这里的
abc
abc
都是不同的

为什么不使用LINQ?首先,我将从搜索字符串中删除sapces:

str = str.Replace(" ", "");
foundRows = datatable1.AsEnumerable()
    .Where(row => row.Field<string>("a").Split().Contains(str))
    .ToArray();
str=str.Replace(“,”);
foundRows=datatable1.AsEnumerable()
.Where(row=>row.Field(“a”).Split()包含(str))
.ToArray();
如果要忽略空格,请执行以下操作:

foundRows = datatable1.AsEnumerable()
    .Where(row => row.Field<string>("a").Replace(" ", "") == str)
    .ToArray();
foundRows=datatable1.AsEnumerable()
.Where(row=>row.Field(“a”).Replace(“,”)==str)
.ToArray();

为什么不使用LINQ?首先,我将从搜索字符串中删除sapces:

str = str.Replace(" ", "");
foundRows = datatable1.AsEnumerable()
    .Where(row => row.Field<string>("a").Split().Contains(str))
    .ToArray();
str=str.Replace(“,”);
foundRows=datatable1.AsEnumerable()
.Where(row=>row.Field(“a”).Split()包含(str))
.ToArray();
如果要忽略空格,请执行以下操作:

foundRows = datatable1.AsEnumerable()
    .Where(row => row.Field<string>("a").Replace(" ", "") == str)
    .ToArray();
foundRows=datatable1.AsEnumerable()
.Where(row=>row.Field(“a”).Replace(“,”)==str)
.ToArray();

如果我没弄错的话,如果输入是
“abc”,你也应该
str.Replace(“,”)
@mybirthname:老实说,我不知道可能的输入以及应该如何处理它们。但是OP现在应该知道如何修改查询以获得预期的结果。是的,您的解决方案更好。@TimSchmelter:AsEnumerable的汇编引用是什么?@shafi7468:您需要
使用System.Linq
和对
System.Data.DataSetExtensions.dll的引用
(for)如果我没有弄错,您也应该
str.Replace(“,”)
,如果输入是
“a B C”@mybirthname:老实说,我不知道可能的输入以及应该如何处理它们。但是OP现在应该知道如何修改查询以获得预期的结果。是的,您的解决方案更好。@TimSchmelter:AsEnumerable的汇编引用是什么?@shafi7468:您需要
使用System.Linq
和对
System.Data.DataSetExtensions.dll的引用
a B D
是否为匹配记录?您还没有解释您的要求。
A B D
是匹配的记录吗?你还没有解释你的要求。