Sql 无法执行';比如';对System.Int32和System.String的操作

Sql 无法执行';比如';对System.Int32和System.String的操作,sql,vb.net,gridview,Sql,Vb.net,Gridview,当我尝试为我的CertificateID列添加搜索文本框时,出现此错误。我知道这是因为您不能使用“like”操作,因为我的CertificateID列是int32而不是字符串。我只是不知道应该用什么代码来让它工作。我尝试了Cast()函数,但没有任何运气。谁能帮我查一下密码吗。 我正在使用filterexpression筛选我的数据: FilterExpression="[CertificateID] like '{0}%' and [Customs_Entry] like '{0}%' and

当我尝试为我的CertificateID列添加搜索文本框时,出现此错误。我知道这是因为您不能使用“like”操作,因为我的CertificateID列是int32而不是字符串。我只是不知道应该用什么代码来让它工作。我尝试了Cast()函数,但没有任何运气。谁能帮我查一下密码吗。 我正在使用filterexpression筛选我的数据:

FilterExpression="[CertificateID] like '{0}%' and [Customs_Entry] like '{0}%' and [Product_Number] like '{1}%' and [Product_Name] like '{2}%'">

<asp:ControlParameter ControlID="txtCertificateID_Filter" Name="CertificateID" PropertyName="Text" Type="String" ConvertEmptyStringToNull="false" />
试一试

您可以将10更改为任何适当的值

编辑 好的,那么它就不能访问SQL server了,您试过了吗

Convert(Product_Number , 'System.String') LIKE '{1}%'

你试过转换吗

convert(varchar(length),[CertificateID]) like '{0}%'
使用此代码

"Convert(" + Your Column Name + ",'System.String')" + " LIKE '*" + Searching Text + "*'"

我尝试过:CAST(CertificateID为varchar(10))类似于“{1}%”,但我得到了一个错误:表达式包含未定义的函数调用CAST()。好的,使用Convert(Product_Number,'System.String')类似于“{1}%”,我能够加载页面,但是当我进入搜索时,无论在任何框中键入什么,gridview都不会返回任何结果。但如果它们为空,gridview将填充所有记录。谢谢你的帮助!我回答了您最初的问题了吗?当我尝试加载页面时,它消除了错误,但搜索结果中现在没有显示任何内容。您可能希望将“and”s更改为“and”或“s”,但我认为初始问题已得到纠正。我尝试了转换,但出现了错误:表达式包含未定义的函数调用varchar()。
Convert(Product_Number , 'System.String') LIKE '{1}%'
convert(varchar(length),[CertificateID]) like '{0}%'
"Convert(" + Your Column Name + ",'System.String')" + " LIKE '*" + Searching Text + "*'"