我正在从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() + "]";