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.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
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

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

Left by mgthantzin at 3/17/2010 1:47 AM
Gravatar
You can use StringBuilder to build the string. It solves the problem for me.

Your comment:



(not displayed)


 
 
 
 
 

Live Comment Preview:

 
«February»
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
26272829123
45678910