字符串格式不同于.. [英] String format different than..

查看:81
本文介绍了字符串格式不同于..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我试图过滤数据表,我正在使用它并且它有效:

 DataRow [] rowsTarget = dt3 .Select( string  .Format(  CodigoKitDC = {0 },row [  Items])); 

但现在我需要剩下的其他数据,



如何使用不同的字符串格式,如下所示:

  string  .Format(  CodigoKitDC ! =  {0},行[ 项目])) ; 

但它不是Works.help请



我尝试过:



 string.Format(CodigoKitDC !=  {0},row [Items])); 

 string.Format(CodigoKitDC <>  {0},row [Items])); 

解决方案

我用谷歌搜索数据表选择不等于这是第一个结果



datatable - c#如何指定不在选择中声明? - 堆栈溢出 [ ^ ]



请在提出问题之前进行基本研究,例如搜索。


由于表达式是字符串文字,因此必须使用SQL语法,因此 <> 是正确的不平等运算符。



说但它不起作用并没有给我们足够的信息来帮助你。将您的代码放入 try / catch 块中,这样您就可以看到生成的异常(如果有的话)。



到此处获取Select方法表达式的有效运算符的完整列表。你需要在页面的中间滚动:



DataColumn.Expression属性(System.Data) [ ^ ]


那是因为过滤器使用<>不是!=表示不等于。

尝试

 string.Format(CodigoKitDC<> {0},行[ 文件])); 


Hello

Im trying to filter a datatable, i´m using this and it works:

DataRow[] rowsTarget = dt3.Select(string.Format("CodigoKitDC={0}", row["Items"]));

but now i need to have the rest of the data,

how can i make a string format with the different, something like this:

string.Format("CodigoKitDC != {0}", row["Items"]));

but it not Works.help please

What I have tried:

string.Format("CodigoKitDC != {0}", row["Items"]));

string.Format("CodigoKitDC <> {0}", row["Items"]));

解决方案

I googled "datatable select not equal" and this was the first result

datatable - c# How do I specify a not in a select statement? - Stack Overflow[^]

Please do basic research such as searching before you ask a question.


Since the expression is in a string literal, you have to use SQL syntax, thus "<>" is the correct inequality operator.

Saying "but it not work" does not give us enough information to help you further. Put your code into a try/catch block so you can see the exception being generated (if any).

Go here for a complete list of valid operators for the Select method expression. You'll need to scroll about halfway down the page:

DataColumn.Expression Property (System.Data)[^]


That's because the filter uses "<>" not "!=" for "not equal to".
Try

string.Format("CodigoKitDC <> {0}", row["Items"]));


这篇关于字符串格式不同于..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆