samedi 25 avril 2015

Search gridview asp.net


I get the following error when I do a date range search in my asp.net program.

Conversion failed when converting date and/or time from character string

here is the code for the search . Please help. I also want to display only date and not date and time in my grid view.

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
        AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource2">
        <Columns>
            <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
                SortExpression="ID" />
            <asp:BoundField DataField="Story_number" HeaderText="Story_number" SortExpression="Story_number" />
            <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
            <asp:BoundField DataField="Memory_card" HeaderText="Memory_card" SortExpression="Memory_card" />
            <asp:BoundField DataField="Story_Name" HeaderText="Story_Name" SortExpression="Story_Name" />
        </Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:IngestConnectionString %>"
        SelectCommand="SELECT ID, Story_number, Date, Memory_card, Story_Name FROM Library WHERE (Story_Name LIKE '%' + @Story_Name + '%') AND (Story_number LIKE '%' + @Story_number + '%')   AND (@startDate IS NULL OR Date >= @startdate) AND (@enddate IS NULL or Date <= @enddate)">
        <SelectParameters>
            <asp:ControlParameter ControlID="TextBox1" Name="Story_Name" PropertyName="Text"
                DefaultValue="%" />
            <asp:ControlParameter ControlID="TextBox2" DefaultValue="%" Name="Story_number" PropertyName="Text" />
            <asp:ControlParameter ControlID="TextBox3" DefaultValue="" Name="startdate" PropertyName="Text" />
            <asp:ControlParameter ControlID="TextBox4" Name="enddate" DefaultValue="" PropertyName="Text" />
 </asp:SqlDataSource>


Aucun commentaire:

Enregistrer un commentaire