Error: "Cannot perform 'Like' operation on System.Int64 and System.String"

I've had a code similar to the following:

string sSql = String.Format("Column1 LIKE '%{0}%'", StringValue);
fareRows = dataset.Table.Select(sSql);

And DataTable.Select method returned me  "Cannot perform 'Like' operation on System.Int64 and System.String".

System.Data.EvaluateException: Cannot perform 'Like' operation on System.Int64 and System.String.

   at System.Data.BinaryNode.SetTypeMismatchError(Int32 op, Type left, Type right)

   at System.Data.LikeNode.Eval(DataRow row, DataRowVersion version)

   at System.Data.Select.AcceptRecord(Int32 record)

   at System.Data.Select.GetLinearFilteredRows(Range range)

   at System.Data.Select.SelectRows()

   at System.Data.DataTable.Select(String filterExpression)

 I've checked http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataDataColumnClassExpressionTopic.asp and it  didn't help.
After some debugging I recognized that I've used incorrect Column1  name and the column that I've used for filtering had integer type. So the error description is not obvious, but gives a mearningful hint.

I am not sure, that I should post this, but it could help people, who "Google first" instead of "think first"(like me in this case).  
Update: I was surprised that there are guite a few hits to this post from Google searches for the error.

posted @ Sunday, July 15, 2007 11:39 AM

Print

Comments on this entry:

# re: Error: "Cannot perform 'Like' operation on System.Int64 and System.String"

Left by Aravindakumar.V at 6/5/2008 1:48 AM
Gravatar
I have come across this problem and I had this fix, the datacolumn you are filtering could be interger

Your comment:



 (will not be displayed)


 
 
 
Please add 2 and 2 and type the answer here:
 

Live Comment Preview:

 
«October»
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678