Hi All,
with the below code I am trying to select the number of unique visits by IP address between a date to another using Ajax Calendar extender but it doesn't work:
(P.S. the query does work if I use it in the query functionality of SSMS 2014):
<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>
In code behind:
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 SubDo you know what's wrong with the above code?
No particular errors is thrown but the error message that I implemented above.
Thanks