Character constant must contain exactly one character

5.4k Views Asked by At

When you get this error "Character constant must contain exactly one character"

I had this code but it constant gave me the above error in my LinqDataSource:

 <asp:LinqDataSource ID="LinqViewLogs" runat="server" 
    ContextTypeName="ScanFakDataContext" OrderBy="Dato desc" 
    TableName="ViewLogs" 
        Where="(@Filter='' OR (@Filter='UserNotes' AND LogType=1)">
     <WhereParameters>
         <asp:QueryStringParameter DbType="String" DefaultValue="" Name="Filter" QueryStringField="Filter" />
     </WhereParameters>
</asp:LinqDataSource>
1

There are 1 best solutions below

1
JanBorup On

The problem was to reverse the quotes, so "" is '', and '' was ""

Here is the correct code:

 <asp:LinqDataSource ID="LinqViewLogs" runat="server" 
    ContextTypeName="ScanFakDataContext" OrderBy="Dato desc" 
    TableName="ViewLogs" 
        Where='(@Filter="" OR (@Filter="UserNotes" AND LogType=1)'>
     <WhereParameters>
         <asp:QueryStringParameter DbType="String" DefaultValue="" Name="Filter" QueryStringField="Filter" />
     </WhereParameters>
</asp:LinqDataSource>