Click here to Skip to main content
12,693,693 members (36,530 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server
Dear Friends,
am working on asp.net , C#, SqlServer 2005.
I want to redirect it to Underconstruction page if time is not updating.
if database time is less than 5 minutes when compare to system time...it must redirect to underconstruction page. else it should be Home.aspx.
This is my code.
protected void Page_Load(object sender, EventArgs e)
    {
       // lblUpdate.Text = "Last Updated at : " + DateTime.Now.AddMinutes(-60).ToLongTimeString();

       SqlConnection con = new SqlConnection("Data Source=IT-PC;Initial Catalog=collegeDB;User ID=sa; Password=12345;");
       

        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "Select timeupdate from timeLastUpdate";

        using (con)
        {
            con.Open();
            SqlDataReader reader = cmd.ExecuteReader();

            if (reader.Read())
            {
                lblUpdate.Text = reader["timeupdate "].ToString();

                lblUpdate.ForeColor = Color.Red;
            }
        }
}

If time updating stops it must redirect to underconstructionpage.aspx
else
redirect to Home.aspx
Please help me, Thanks.
Posted 9-Oct-12 21:59pm
Updated 9-Oct-12 22:01pm
tanweer15.4K
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

hi, it will work:
protected void Page_Load(object sender, EventArgs e)
    {
            // lblUpdate.Text = "Last Updated at : " + DateTime.Now.AddMinutes(-60).ToLongTimeString();

            SqlConnection con = new SqlConnection("Data Source=IT-PC;Initial Catalog=collegeDB;User ID=sa; Password=12345;");

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;
            cmd.CommandText = "Select timeupdate from timeLastUpdate";

            using (con)
            {
                con.Open();
                SqlDataReader reader = cmd.ExecuteReader();

                if (reader.Read())
                {
                    lblUpdate.Text = reader["timeupdate "].ToString();

                    lblUpdate.ForeColor = Color.Red;

                    if (Convert.ToDateTime(reader["timeupdate "].ToString()) < DateTime.Now.AddMinutes(-5))
                    {
                        Response.Redirect("underconstructionpage.aspx");
                    }
                }
            }
    }
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi Use the below code
protected void Page_Load(object sender, EventArgs e)
    {
       // lblUpdate.Text = "Last Updated at : " + DateTime.Now.AddMinutes(-60).ToLongTimeString();
       SqlConnection con = new SqlConnection("Data Source=IT-PC;Initial Catalog=collegeDB;User ID=sa; Password=12345;");       
 
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandText = "Select timeupdate from timeLastUpdate";
        DateTime lastupdatetime;
        using (con)
        {
            con.Open();
            SqlDataReader reader = cmd.ExecuteReader();
 
            if (reader.Read())
            {
                lastupdatetime = Convert.ToDateTime(reader["timeupdate "].ToString());
                lblUpdate.Text = lastupdatetime.ToString();
                lblUpdate.ForeColor = Color.Red;
            }
        }
        if(lastupdatetime.AddMinutes(5) > DateTime.Now)
        {
            Response.Redirect("HomePage.aspx");
        }
        else
        {
            Response.Redirect("underconstruction.aspx");

         }
}

Also you should clean all the resources.
  Permalink  
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

I think you can write that code at Global.asax file at session start to get time from the database and then compare it.

if you condition satisfy for less then 5 min then you can directly redirect to underconstrunctionpage.aspx else no redirection. and it will display home.aspx as usual.

I hope this would be helpful. Let me know if you need any further help.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 10 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100