Geeks With Blogs

News My Blog has been MOVED to https://mfreidge.wordpress.com
Michael Freidgeim's OLD Blog My Blog has been MOVED to https://mfreidge.wordpress.com

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 on Sunday, July 15, 2007 11:39 AM .Net Framework | Back to top


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

# re: Error: "Cannot perform 'Like' operation on System.Int64 and System.String"
Requesting Gravatar...
I have come across this problem and I had this fix, the datacolumn you are filtering could be interger
Left by Aravindakumar.V on Jun 05, 2008 1:48 AM

# re: Error: "Cannot perform 'Like' operation on System.Int64 and System.String"
Requesting Gravatar...
You can use StringBuilder to build the string. It solves the problem for me.
Left by mgthantzin on Mar 17, 2010 1:47 AM

# Cannot perform '=' operation on System.UInt64 and System.String.
Requesting Gravatar...
Plz help how to solve?
Left by Latha on Sep 20, 2015 2:34 AM

Your comment:
 (will show your gravatar)


Copyright © Michael Freidgeim | Powered by: GeeksWithBlogs.net