无法在System.Int32和System.String上执行“Like”操作。 [英] Cannot perform 'Like' operation on System.Int32 and System.String.

查看:138
本文介绍了无法在System.Int32和System.String上执行“Like”操作。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Highlight the Search Keywords in Gridview </title>
<style type="text/css">
.GridviewDiv {font-size: 100%; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helevetica, sans-serif; color: #303933;}
Table.Gridview{border:solid 1px #df5015;}
.Gridview th{color:#FFFFFF;border-right-color:#abb079;border-bottom-color:#abb079;padding:0.5em 0.5em 0.5em 0.5em;text-align:center}
.Gridview td{border-bottom-color:#f0f2da;border-right-color:#f0f2da;padding:0.5em 0.5em 0.5em 0.5em;}
.Gridview tr{color: Black; background-color: White; text-align:left}
:link,:visited { color: #DF4F13; text-decoration:none }
.highlight {text-decoration: none;color:black;background:yellow;}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="GridviewDiv">
<p>
Enter UserName :
<asp:TextBox ID="txtSearch" runat="server"  />&nbsp;&nbsp;
<asp:ImageButton ID="btnSearch" ImageUrl="~/SearchButton.png" runat="server"

Style="top: 5px; position: relative" onclick="btnSearch_Click" />&nbsp;&nbsp;
<asp:ImageButton ID="btnClear" ImageUrl="~/Clearbutton.png" runat="server" Style="top: 5px;
position: relative" onclick="btnClear_Click" /><br />
<br />
</p>
<asp:GridView ID="gvDetails" runat="server" AutoGenerateColumns="False" AllowPaging="True"

AllowSorting="True" DataSourceID="dsDetails" Width="540px" CssClass="Gridview"

            DataKeyNames="voucherID" >
<HeaderStyle BackColor="#df5015" />
<Columns>
    <asp:BoundField DataField="voucherID" HeaderText="voucherID" InsertVisible="False"

        ReadOnly="True" SortExpression="voucherID" />
    <asp:BoundField DataField="voucher" HeaderText="voucher"

        SortExpression="voucher" />
    <asp:BoundField DataField="RS" HeaderText="RS"

        SortExpression="RS" />
    <asp:BoundField DataField="CPoints" HeaderText="CPoints"

        SortExpression="CPoints" />
    <asp:BoundField DataField="Datec" HeaderText="Datec" SortExpression="Datec" />
</Columns>
</asp:GridView>
</div>

<asp:AccessDataSource ID="dsDetails" runat="server"

        DataFile="~/App_Data/DatabasePCG03.mdb"

        SelectCommand="SELECT * FROM [coupen]"



        FilterExpression="voucherID LIKE '%{0}%' OR voucher LIKE '%{0}%' OR RS LIKE '%{0}%'OR CPoints LIKE '%{0}%'OR Datec LIKE '%{0}%'">
<FilterParameters>
<asp:ControlParameter Name="voucherID" ControlID="txtSearch" PropertyName="Text" />
<asp:ControlParameter Name="voucher" ControlID="txtSearch" PropertyName="Text" />
<asp:ControlParameter Name="RS" ControlID="txtSearch" PropertyName="Text" />
<asp:ControlParameter Name="CPoints" ControlID="txtSearch" PropertyName="Text" />
<asp:ControlParameter Name="Datec" ControlID="txtSearch" PropertyName="Text" />

</FilterParameters>
</asp:AccessDataSource>
</form>
</body>
</html>

推荐答案

就像你不应该使用整数值。你可以检查在OR条件之前是否有空白区域。我可以在两个地方看到你错过了它(RS LIKE''%{0}%''或CPoints LIKE''%{0}%''或Datec)。



LIKE you shouldn''t be doing with integer values. Can you check if putting white-space before OR condition helps with this. I can see at two places you have missed it(RS LIKE ''%{0}%''OR CPoints LIKE ''%{0}%''OR Datec).

voucherID LIKE ''%{0}%'' OR voucher LIKE ''%{0}%'' OR RS LIKE ''%{0}%'' OR CPoints LIKE ''%{0}%'' OR Datec LIKE ''%{0}%''


LIKE 表达式仅适用于字符串和字符串列。你不能使用 LIKE 的整数或数字列,除非你将涉及的数字转换为字符串。
The LIKE expression only works on strings and string columns. You can''t use an integer or numeric column with LIKE, well, unless you convert the number involved to a string.


这篇关于无法在System.Int32和System.String上执行“Like”操作。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆