Reputation: 1017
I'm retrieving data from excel and one of the column in excel has '#' like "POLICY #" is the name of the column in excel.
Here is my code
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
}
}
The value of the _policyNoColumn is "POLICY #". and this what i'm getting.
The expression contains invalid date constant '# = 'V0263680''.
And Here is the source error
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: {
Highlighted part is Line 503
.
Upvotes: 3
Views: 2804
Reputation: 1017
I got the answer
Here what i Did
string _policyNoColumn = "[" + dtFile.Columns[1].ToString() + "]";
Upvotes: 4