【发布时间】:2015-03-26 10:42:55
【问题描述】:
使用下面的代码,我试图通过 IP 地址选择 2 个日期之间的唯一访问次数,并在标签中显示结果。我正在使用 Ajax 日历扩展器在日期之间进行过滤,但它不起作用,我从 2 天以来一直在尝试解决这个头痛问题,但没有机会在 Internet 上找到完整的东西(附注:如果我在SSMS 2014 的查询功能):
这是我的 .aspx 页面代码:
<asp:Label ID="Label1" runat="server" Text="Start Date"></asp:Label>
<asp:TextBox ID="StartDateTextBox" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="StartDateTextBox" Format="dd/MM/yyyy" Enabled="True"></cc1:CalendarExtender>
<asp:Label ID="Label2" runat="server" Text="End Date"></asp:Label>
<asp:TextBox ID="EndDateTextBox" runat="server"></asp:TextBox>
<cc1:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="EndDateTextBox" Format="dd/MM/yyyy" Enabled="True"></cc1:CalendarExtender>
<asp:Button ID="showbtn" runat="server" Text="Button" onclick="showvisits"/>
<asp:Label ID="uniquevisits" runat="server" Text=""></asp:Label>
<asp:Label ID="failure" runat="server" Text=""></asp:Label>
在后面的代码中:
Protected Sub showvisits(sender As Object, e As EventArgs) Handles showbtn.Click
Dim conn As New SqlConnection(ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString)
Try
conn.Open()
Dim cmd As New SqlCommand("SELECT COUNT (DISTINCT VisitIp) FROM IpStorage WHERE VisitDate BETWEEN '@StartDate' AND '@EndDate')", conn)
cmd.Parameters.AddWithValue("@StartDate", DateTime.Parse(StartDateTextBox.Text))
cmd.Parameters.AddWithValue("@EndDate", DateTime.Parse(EndDateTextBox.Text))
Dim myReader As SqlDataReader = cmd.ExecuteReader()
While myReader.Read()
uniquevisits.Text = myReader("VisitIp").ToString()
End While
myReader.Close()
Catch ex As SqlException
failure.Text = "ERROR"
Finally
conn.Close()
End Try
End Sub
你知道上面的代码有什么问题吗?
没有抛出特定错误,但我在上面在 failure.Text 标签中实现的错误消息
非常感谢您的帮助
【问题讨论】:
标签: asp.net vb.net date asp.net-ajax calendarextender