简体   繁体   中英

Getting record between two dates

I want to connect to SQL database and filter my record based on date with year and month and date and hours.

I can display all record between last day 7 am to system date but I want to created the button as name as filtering and two text box as name as start date and end date.

In the code behind I can't connect to my network pass.please help me

    <UpdateParameters>

    <asp:Parameter Type="String" name="RfidDate"></asp:Parameter>
    <asp:Parameter Type="String" name="InorOut"></asp:Parameter>

        <asp:Parameter Type="String" Name="codemahsol" />
        <asp:Parameter Type="String" Name="shomarekhatetolid" />
        <asp:Parameter Type="string" Name="tmahsol" />

        <asp:Parameter Type="string" Name="DESC" />


    </UpdateParameters>
    </asp:SqlDataSource>
    <table class="style" runat="server">
        <tr>
            <td colspan="2" style="text-align:center">
                <b>Filtring message between date</b></td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="lblstartdate" runat="server" Text="starting date"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="txtstartingdate" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="lblendingdate" runat="server" Text="ending date"></asp:Label>
            </td>
            <td>
                <asp:TextBox ID="txtendingdate" runat="server"></asp:TextBox>
            </td>
        </tr>
        <tr>
            <td>
                <asp:Label ID="lblfilter" runat="server" Text="Filtering"></asp:Label>
            </td>
            <td>
                <asp:Button ID="btnfilter" runat="server" Text="Filtering" Width="81px" OnClick="btnfilter_click" />
            </td>
        </tr>
    </table>
    <asp:GridView ID="gdvRfids" runat="server" DataSourceID="sdsRfids" AllowPaging="false" AllowSorting="true" AutoGenerateColumns="false" >
    <PagerStyle BackColor="Gray" ForeColor="White" HorizontalAlign="Center" />
    <HeaderStyle BackColor="Black" ForeColor="White" />
    <AlternatingRowStyle BackColor="LightGray" />
    <columns>
    <asp:CommandField ButtonType="Button" ShowEditButton="false" />

        <asp:BoundField HeaderText="codemahsol" DataField="codemahsol" SortExpression="codemahsol" />
        <asp:BoundField HeaderText="tmahsol" DataField="tmahsol" SortExpression="tmahsol" />
        <asp:BoundField HeaderText="shomarekhatetolid" DataField="shomarekhatetolid" SortExpression="shomarekhatetolid" />

             <asp:BoundField HeaderText="InorOut" DataField="InorOut" SortExpression="InorOut" >
                 </asp:BoundField>

        <asp:BoundField HeaderText="DESC" DataField="DESC" SortExpression="DESC" />
        <asp:TemplateField HeaderText="select">
            <ItemTemplate>
                <asp:CheckBox ID="chkselect" runat="server" />
            </ItemTemplate>
            <HeaderTemplate>
            </HeaderTemplate>
        </asp:TemplateField>
        <asp:BoundField />
        </columns> 
 </asp:GridView>
    <asp:Button ID="btnGetRecord" Text="Get Selected Records" runat="server" Font-Bold="true" OnClick="btnGetRecord_Click" /><br /><br />
    <asp:Label ID="lblRecord" runat="server"></asp:Label>
</div>
</form>
<script type="text/javascript">
    function CheckAll(Checkbox) {
        var DridVwHeaderCheckbox = document.getElementsByTagName("<%=gdvRfids %>");
        for (i = 1; i < DridVwHeaderCheckbox.row.lenght; i++) {
            DridVwHeaderCheckbox.row[i].cell[0].getElementsByTagName("INPUT")
            [0].checked = Checkbox.checked;
        }
    }
</script>

You need to convert the date into MM/dd/yyyy HH:mm format and get the records in the database

DataRow[] TempRow = Table.Select("((Entry_Time) >= #" + 
      StartDate.ToString("MM/dd/yyyy HH:mm", System.Globalization.CultureInfo.InvariantCulture) + "#) AND ((Entry_Time)<=#" +
      EndDate.ToString("MM/dd/yyyy HH:mm", System.Globalization.CultureInfo.InvariantCulture) + "#)");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM