You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

DataTable双列过滤Select语句编译错误,求修正方法

DataTable双列筛选代码编译错误修复

你的代码编译错误的核心原因是错误拆分了Select方法的筛选条件——and应该放在Select的筛选字符串内部,而非在两个方法调用之间拼接。

正确的基础写法

将两个筛选条件合并为一个完整字符串,用AND连接后传入Select方法:

in_dt_WPSFileInput.Select("PatientMedicareNumber='"+in_str_PatientMedicareNumber+"' AND DateofServiceStart='"+in_str_DateofServiceStart+"'").CopyToDataTable

日期类型字段的额外注意

如果DateofServiceStart是日期类型,不要用单引号包裹日期值,应改用井号(#),否则可能出现运行时类型匹配错误:

in_dt_WPSFileInput.Select("PatientMedicareNumber='"+in_str_PatientMedicareNumber+"' AND DateofServiceStart=#"+in_str_DateofServiceStart+"#").CopyToDataTable

更安全的替代方案

为避免字符串拼接的潜在问题(比如特殊字符、SQL注入风险),推荐使用LINQ查询的方式:

var filteredRows = in_dt_WPSFileInput.AsEnumerable()
    .Where(row => row.Field<string>("PatientMedicareNumber") == in_str_PatientMedicareNumber
                && row.Field<DateTime>("DateofServiceStart").ToString("yyyy-MM-dd") == in_str_DateofServiceStart)
    .CopyToDataTable();

内容的提问来源于stack exchange,提问作者Arun Singh G

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 10:42:03