locked
Filter selected date from calendar to display chart reading from database RRS feed

  • Question

  • User1391648435 posted

    Hi guys, 
    i would like to know how to Filter selected date from calendar to display chart reading from database using web application from visual studio aspx page
    Is there a way to do it? 

    Friday, March 24, 2017 8:19 AM

Answers

All replies

  • User-271186128 posted

    Hi JovanYong,

    i would like to know how to Filter selected date from calendar to display chart reading from database using web application from visual studio aspx page
    Is there a way to do it? 

    You could use JQuery DatePicker or Asp.net Calendars control to selected date. Please refer to the following links:

    https://jqueryui.com/datepicker/

    https://www.tutorialspoint.com/asp.net/asp.net_calenders.htm

    Then, refer to the following code to filter data from database:

    using (SqlConnection con = new SqlConnection(strConnect))
                    {
                    con.Open();
                    using (SqlCommand com = new SqlCommand("SELECT * from table where [Date] between @SD and @ED", con))
                        {
                        com.Parameters.AddWithValue("@SD", txtfromDate.Text);
                        com.Parameters.AddWithValue("@ED", txttodate.Text);
                        using (SqlDataReader reader = com.ExecuteReader())
                            {
                            while (reader.Read())
                                {
                                int id = (int) reader["iD"];
                                string desc = (string) reader["description"];
                                Console.WriteLine("ID: {0}\n    {1}", iD, desc);
                                }
                            }
                        }
                    }

    More details, see:

    https://www.codeproject.com/Questions/556502/Howplustoplussearchplusaplusrecordplusfromplusdata

    Finally, refer to the following links to create a chart.

    https://www.aspsnippets.com/Articles/Create-ASPNet-Chart-Control-from-Database-using-C-and-VBNet-Example.aspx

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, March 25, 2017 3:27 AM
  • User1391648435 posted

    Where does your strConnect leads to?

    using (SqlConnection con = new SqlConnection(strConnect))
                    {
                    con.Open();
                    using (SqlCommand com = new SqlCommand("SELECT * from table where [Date] between @SD and @ED", con))
                        {
                        com.Parameters.AddWithValue("@SD", txtfromDate.Text);
                        com.Parameters.AddWithValue("@ED", txttodate.Text);
                        using (SqlDataReader reader = com.ExecuteReader())

    Tuesday, March 28, 2017 1:28 AM
  • User1391648435 posted

    Thanks alot! You help me alot (: !!!!!!

    Tuesday, March 28, 2017 1:49 AM