如何使用fromdate textbox和todate textbox向gridview查询数据 [英] How do I query data to a gridview using fromdate textbox and todate textbox
问题描述
我有一个页面,它将在gridview中生成数据,该数据由文本框中条目之间的人名和数据触发,日期和带有日期的文本框。
我的gridview SQL代码如下所示:
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)和[login_date]之间([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!='')
我无法弄清楚如何将文本框值写入between语句。
我的代码在页面上如下:
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>
推荐答案
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]之间([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 名称 = officer_name PropertyName = SelectedValue / >
< asp:ControlParameter ControlID = TextBoxFromDate < span class =code-attribute>名称 = from_date PropertyName = 文字 / >
< asp:ControlParameter ControlID = TextBoxToDate 名称 = to_date PropertyName = 文字 / >
< / SelectParameters >
< / asp:SqlDataSource >
< / strong >
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>
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]之间([login_date] = convert(datetime,@ from_date,103))AND([login_date] = convert(datetime,@ to_date,103))AND(log_in IS NOT NULL)AND(log_out IS NOT NULL)AND(log_in! ='')AND(log_out!='')
尝试使用此代码传递文本框值es as @ from_date,@ to_date
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] =convert(datetime,@from_date,103)) AND ([login_date] = convert(datetime,@to_date,103)) AND (log_in IS NOT NULL) AND (log_out IS NOT NULL) AND (log_in !='') AND (log_out !='')
Try With this code by passing textbox values as @from_date,@to_date
这篇关于如何使用fromdate textbox和todate textbox向gridview查询数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!