Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Connectionless Calendar?

Connectionless Calendar?

Scheduled Pinned Locked Moved ASP.NET
questioncsharpdatabasedesignhelp
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HahnTech
    wrote on last edited by
    #1

    I’m having some troubles understanding how disconnected Db work with a web app. I’ll show you what I have, what I’m trying to do, and then what isn’t working. I have a page with a calendar control and within each day I want to display data from timetable for that day but I don’t want to have to hit the db for each day nor do I want to hit the Db each time I select a day from the calendar. Only on the selection of a new month should the Db be hit. private void Page_Load(object sender, System.EventArgs e) { if(!this.IsPostBack) { string SQLq = "SELECT Time" + "FROM timeTable " + "WHERE employee = @ID " //+ "AND date between @DStart and @DEnd “ + "AND employee = @ID " + "AND Tskname != 'PT'"; using(SqlConnection Conn = new SqlConnection(this.GetCon)) { SqlCommand cmd = new SqlCommand(SQLq, Conn);//SqlCommand(Conn.CreateCommand());// cmd.CommandType=CommandType.Text; //cmd.Parameters.Add("@DStart", SqlDbType.DateTime).Value = e.Day.Date; cmd.Parameters.Add("@ID", SqlDbType.Int).Value = User.Identity.Name.Split()[(int)UserInfo.UserSID]; My_Da.SelectCommand=cmd; My_Da.Fill(My_Ds); } } I’m also looking for a way to figure out what month it is so I only have to pull one month at a time. private void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e) { string cellText = ""; double iDayTotal = 0; short Count = 0; DataView DayView = new DataView(My_Ds.Tables[0]); DayView.RowFilter = "Date = '" + e.Day.Date.ToString() + "'"; foreach(DataRowView row in DayView) { iDayTotal += (double)row["Total"]; } e.Cell.Controls.Add(new LiteralControl ( " Days Total: " )); } This works for the first month (by default this month) but on any post back I get an exception. The DataSet is invalid. How do I get the PageClass members to remain between postbacks so I only have to hit the Db once per month. Also any idea how I can Figure out what month the calendar will be on so I know what to use in my Date Between clause. Any Help is much appreciated. MSDN best practices has a good explanation of what I want to work but I can’t seem to figure out where to put what code:doh:. Ronald Hahn, CNT - Computer Engineering Technologist New Technologies Analyst HahnTech Affiliated With Code Constructors Edmonton, Alberta, Canada Email: rhahn82@telus.net

    C 1 Reply Last reply
    0
    • H HahnTech

      I’m having some troubles understanding how disconnected Db work with a web app. I’ll show you what I have, what I’m trying to do, and then what isn’t working. I have a page with a calendar control and within each day I want to display data from timetable for that day but I don’t want to have to hit the db for each day nor do I want to hit the Db each time I select a day from the calendar. Only on the selection of a new month should the Db be hit. private void Page_Load(object sender, System.EventArgs e) { if(!this.IsPostBack) { string SQLq = "SELECT Time" + "FROM timeTable " + "WHERE employee = @ID " //+ "AND date between @DStart and @DEnd “ + "AND employee = @ID " + "AND Tskname != 'PT'"; using(SqlConnection Conn = new SqlConnection(this.GetCon)) { SqlCommand cmd = new SqlCommand(SQLq, Conn);//SqlCommand(Conn.CreateCommand());// cmd.CommandType=CommandType.Text; //cmd.Parameters.Add("@DStart", SqlDbType.DateTime).Value = e.Day.Date; cmd.Parameters.Add("@ID", SqlDbType.Int).Value = User.Identity.Name.Split()[(int)UserInfo.UserSID]; My_Da.SelectCommand=cmd; My_Da.Fill(My_Ds); } } I’m also looking for a way to figure out what month it is so I only have to pull one month at a time. private void Calendar1_DayRender(object sender, System.Web.UI.WebControls.DayRenderEventArgs e) { string cellText = ""; double iDayTotal = 0; short Count = 0; DataView DayView = new DataView(My_Ds.Tables[0]); DayView.RowFilter = "Date = '" + e.Day.Date.ToString() + "'"; foreach(DataRowView row in DayView) { iDayTotal += (double)row["Total"]; } e.Cell.Controls.Add(new LiteralControl ( " Days Total: " )); } This works for the first month (by default this month) but on any post back I get an exception. The DataSet is invalid. How do I get the PageClass members to remain between postbacks so I only have to hit the Db once per month. Also any idea how I can Figure out what month the calendar will be on so I know what to use in my Date Between clause. Any Help is much appreciated. MSDN best practices has a good explanation of what I want to work but I can’t seem to figure out where to put what code:doh:. Ronald Hahn, CNT - Computer Engineering Technologist New Technologies Analyst HahnTech Affiliated With Code Constructors Edmonton, Alberta, Canada Email: rhahn82@telus.net

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      The problem I think is that Calendar1_DayRender is trying to use a dataset which you've not filled. Why don't you just work out DayTotal and store it ? It looks to me like you're doing the same calculation every time. You could store it in Viewstate yourself, by overloading SaveViewState and LoadViewState. Christian Graus - Microsoft MVP - C++

      H 1 Reply Last reply
      0
      • C Christian Graus

        The problem I think is that Calendar1_DayRender is trying to use a dataset which you've not filled. Why don't you just work out DayTotal and store it ? It looks to me like you're doing the same calculation every time. You could store it in Viewstate yourself, by overloading SaveViewState and LoadViewState. Christian Graus - Microsoft MVP - C++

        H Offline
        H Offline
        HahnTech
        wrote on last edited by
        #3

        Yes your right. I guess I simplified my example a bit too much, there is other data from the Db that I will be displaying in the Calendar I just limited it to total for simplicity. But you see what my problem is? If this was a windows form the DataSet member would be persistent. I can’t figure out how to do that in a web for environment. By the way thanks for your help.. You’ve help me in the past and you seem to be one of a verry few that seem to know what there doing and be able to explain your self Ronald Hahn, CNT - Computer Engineering Technologist New Technologies Analyst HahnTech Affiliated With Code Constructors Edmonton, Alberta, Canada Email: rhahn82@telus.net

        C 1 Reply Last reply
        0
        • H HahnTech

          Yes your right. I guess I simplified my example a bit too much, there is other data from the Db that I will be displaying in the Calendar I just limited it to total for simplicity. But you see what my problem is? If this was a windows form the DataSet member would be persistent. I can’t figure out how to do that in a web for environment. By the way thanks for your help.. You’ve help me in the past and you seem to be one of a verry few that seem to know what there doing and be able to explain your self Ronald Hahn, CNT - Computer Engineering Technologist New Technologies Analyst HahnTech Affiliated With Code Constructors Edmonton, Alberta, Canada Email: rhahn82@telus.net

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          HahnTech wrote: If this was a windows form the DataSet member would be persistent. I can’t figure out how to do that in a web for environment. The obvious way is to shove the dataset into the session, but that's really wasteful of resources, and should be a last resort. Is there too much data for you to store it in viewstate ? Those are your two real options, viewstate will make the page size bigger, so that could be a problem also, if there's tons of it, especially if your users have slow connections. According to this[^] article, you can put stuff in viewstate explicitly, without having to overload LoadViewState and SaveViewState. I'd look into this before considering session state. At the end of the day, you need to weigh up the costs of caching data against the cost of calling the database, and decide in each instance which is a better use of available resources. Christian Graus - Microsoft MVP - C++

          H 1 Reply Last reply
          0
          • C Christian Graus

            HahnTech wrote: If this was a windows form the DataSet member would be persistent. I can’t figure out how to do that in a web for environment. The obvious way is to shove the dataset into the session, but that's really wasteful of resources, and should be a last resort. Is there too much data for you to store it in viewstate ? Those are your two real options, viewstate will make the page size bigger, so that could be a problem also, if there's tons of it, especially if your users have slow connections. According to this[^] article, you can put stuff in viewstate explicitly, without having to overload LoadViewState and SaveViewState. I'd look into this before considering session state. At the end of the day, you need to weigh up the costs of caching data against the cost of calling the database, and decide in each instance which is a better use of available resources. Christian Graus - Microsoft MVP - C++

            H Offline
            H Offline
            HahnTech
            wrote on last edited by
            #5

            Thanks. Someday I'll figure out the "behind-the-scenes" of all this and it will be lots easer. I miss windows programming. Ronald Hahn, CNT - Computer Engineering Technologist New Technologies Analyst HahnTech Affiliated With Code Constructors Edmonton, Alberta, Canada Email: rhahn82@telus.net

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups