本文介绍了如果时间没有更新,请重定向到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友,
正在使用asp.net,C#和SqlServer2005.
如果时间没有更新,我想将其重定向到Underconstruction页面.
如果与系统时间相比,数据库时间少于5分钟...则它必须重定向到建设中页面.否则应该是Home.aspx.
这是我的代码.
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;
}
}
}
如果时间更新停止,则必须重定向到underconstructionpage.aspx
其他
重定向到Home.aspx
谢谢.请帮助我.
If time updating stops it must redirect to underconstructionpage.aspx
else
redirect to Home.aspx
Please help me, Thanks.
推荐答案
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.
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");
}
}
}
}
这篇关于如果时间没有更新,请重定向到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!