I have a page that will produce data in a gridview that is triggered by a persons name and data between entries in a textbox with from date and a textbox with a to date.
my gridview SQL code reads as follows:
SELECT DATEDIFF(hh, log_in,log_out ) AS Total, officer_name, login_date, log_in, log_out FROM [Security_Log] WHERE ([officer_name] = @officer_name) AND [login_date] between ([login_date] =@from_date) AND ([login_date] = @to_date) AND (log_in IS NOT NULL) AND (log_out IS NOT NULL) AND (log_in !='') AND (log_out !='')
I can't figure out how to write the text box values into the between statement.
My Code is like this on the page:
<asp:Button ID="ButtonReset" runat="server" CssClass="auto-style6" Text="Reset Page" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" DataSourceID="SqlDataSourceHoursWorked" GridLines="None">
<Columns>
<asp:BoundField DataField="officer_name" HeaderText="officer_name" SortExpression="officer_name" />
<asp:BoundField DataField="login_date" HeaderText="login_date" SortExpression="login_date" />
<asp:BoundField DataField="log_in" HeaderText="log_in" SortExpression="log_in" />
<asp:BoundField DataField="log_out" HeaderText="log_out" SortExpression="log_out" />
<asp:BoundField DataField="Total" HeaderText="Total" SortExpression="Total" ReadOnly="True" />
</Columns>
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
<PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
<SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#594B9C" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#33276A" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSourceHoursWorked" runat="server" ConnectionString="<%$ ConnectionStrings:CorrectConnectionString %>" SelectCommand="SELECT DATEDIFF(hh, log_in,log_out ) AS Total, officer_name, login_date, log_in, log_out FROM [Security_Log] WHERE ([officer_name] = @officer_name) AND [login_date] between ([login_date] =@from_date) AND ([login_date] = @to_date) AND (log_in IS NOT NULL) AND (log_out IS NOT NULL) AND (log_in !='') AND (log_out !='')">
<SelectParameters>
<asp:ControlParameter ControlID="DDOfficerName" Name="officer_name" PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="TextBoxFromDate" Name="from_date" PropertyName="Text" />
<asp:ControlParameter ControlID="TextBoxToDate" Name="to_date" PropertyName="Text" />
</SelectParameters>
</asp:SqlDataSource>
</strong>