【问题标题】:How filter datatable using Like same SQL query如何使用 Like same SQL 查询过滤数据表
【发布时间】:2016-05-01 03:37:41
【问题描述】:

在 sql server 中,我有一个查询: SELECT * FROM [tableName] WHERE [colName] LIKE '%abc[xyz]%'

同一个查询:

SELECT * FROM [tableName] WHERE [colName] LIKE '%abcx%' OR [colName] LIKE '%abcy%' OR [colName] LIKE '%abcz%' 

在 C# 中,我使用 DataTable.SELECT("colName LIKE '%abc[xyz]%'") => 错误。

如何解决?

【问题讨论】:

  • 你遇到了什么异常?
  • 您的查询中不能有“[”或“]”。为什么不使用与第一个查询相同的 where 语句?

标签: c# sql filter datatable


【解决方案1】:

你在使用 linq 吗? 使用 linq 你可以这样写:

Datatable.Select(x=>x.ColName.Contains("abcx.ColName")||x.ColName.Contains("abcy")||x.ColName.Contains("abcz"));

【讨论】:

    【解决方案2】:

    试试这个:

    DataTable.SELECT("colName LIKE '%abcx%' OR colName LIKE '%abcy%' OR colName LIKE '%abcz%'")
    

    【讨论】:

      猜你喜欢
      • 2014-08-15
      • 1970-01-01
      • 1970-01-01
      • 2019-11-12
      • 2022-11-11
      • 2015-09-15
      • 2018-04-23
      • 1970-01-01
      • 2013-12-26
      相关资源
      最近更新 更多