By definition, LIKE is a string operator.
I would suggest that you need to reconsider your design, but if you're determined to search for numbers with "LIKE", you should have a trigger populate a varchar() version of the field in the table.
Question
Hi when I run my code I get this error:
Cannot perform 'Like' operation on System.Int32 and System.String
I need a way to allow int and varchar but cannot think of a solution for it. I understand that it is to do with the fact my id option is an integer but cannot think of a solution and would really appreciate your help.
Public Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim FilterExpression As String = String.Concat(DropDownList1.SelectedValue, " LIKE " + "'%{0}%'")
SqlDataSource1.FilterParameters.Clear()
SqlDataSource1.FilterParameters.Add(New ControlParameter(DropDownList1.SelectedValue, "TextBox1", "Text"))
SqlDataSource1.FilterExpression = FilterExpression
End Sub
End Class
Solution
By definition, LIKE is a string operator.
I would suggest that you need to reconsider your design, but if you're determined to search for numbers with "LIKE", you should have a trigger populate a varchar() version of the field in the table.
OTHER TIPS
Which version of SQL Server are you using? Depending on the version in the SPROC or TSQL you can run bountiful commands on your data to manipulate it like you may need it to be. A great example would be.
Select TRY_CONVERT(STRING, 12065) is Null