gpt4 book ai didi

c# - 如何处理 DataTable.Select ("") 中的特殊字符?

转载 作者:行者123 更新时间:2023-11-30 15:29:31 25 4
gpt4 key购买 nike

我正在从 excel 中检索数据,excel 中的一列有“#”,例如“POLICY #”是 excel 中列的名称。

这是我的代码

string _policyNoColumn = dtFile.Columns[1].ToString();
string _policyNoRow = string.Empty;
foreach (DataRow _rows in dtFile.Rows)
{
_policyNoRow = _rows[1].ToString();
DataRow[] _rowInFile = dtFile.Select(_policyNoColumn + " = '" + _policyNoRow + "'"); //Check on Excel
if (_rowInFile.Count() == 2)
{
_lstInValid.Add(_policyNoRow); //Invalid
}
}

_policyNoColumn 的值为“POLICY #”。这就是我得到的。

The expression contains invalid date constant '# = 'V0263680''.

这是源错误

Line 501:        {            
Line 502: _policyNoRow = _rows[1].ToString();
Line 503: DataRow[] _rowInFile = dtFile.Select(_policyNoColumn + " = '" + _policyNoRow + "'"); //Check on Excel
Line 504: if (_rowInFile.Count() == 2)
Line 505: {

突出显示的部分是第503行

最佳答案

我得到了答案

这是我做的

string _policyNoColumn = "[" + dtFile.Columns[1].ToString() + "]";

关于c# - 如何处理 DataTable.Select ("") 中的特殊字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23555318/

25 4 0
文章推荐: c - GTK+2 : My App is Crashing on quit
文章推荐: javascript - Vue.js