获取两个日期之间的记录

时间:2015-09-19 06:59:20

标签: c# asp.net sql-server

我想连接到SQL数据库并根据包含年份和月份以及日期和时间的日期过滤我的记录。

我可以显示最后一天早上7点到系统日期之间的所有记录,但我想创建按钮作为名称作为过滤,并将两个文本框作为名称作为开始日期和结束日期。

在后面的代码我无法连接到我的网络pass.please帮助我

    <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>

1 个答案:

答案 0 :(得分:0)

您需要将日期转换为MM/dd/yyyy HH:mm格式并获取数据库中的记录

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) + "#)");