Hello,
How can I pull data from the database to the timer field?
When I try with these codes it gives an error ERR_TOO_MANY_REDIRECTS
public void Veri()
{
string LessonID = string.Empty;
string LessonName = string.Empty;
string LessonStartTime = string.Empty;
var da = new SqlDataAdapter("select * from Dersler", vt.conn());
var dt = new DataTable();
da.Fill(dt);
foreach (DataRow row in dt.Rows)
{
foreach (DataColumn column in dt.Columns)
{
LessonID = row["DersID"].ToString();
LessonName = row["DersAdi"].ToString();
LessonStartTime = row["DersBaslamaSaati"].ToString();
}
}
return dt;
}
protected void TimerTick(object sender, EventArgs e)
{
lblMessage.Text = "";
DataTable dt = Veri();
DateTime currentDateTime = DateTime.Now;
foreach (DataRow dr in dt.Rows)
{
DateTime startTime = Convert.ToDateTime(dr["StartTime"]);
double diff = startTime.Subtract(currentDateTime).TotalSeconds;
if (diff < 300 && diff > 60)
{
lblMessage.Text = string.Format("{0} lession to be start in {1} minutes.",
dr["Lesson"].ToString(), Math.Round(diff / 60, 0));
}
else if (diff < 60 && diff > 0)
{
lblMessage.Text = string.Format("{0} lession to be start in {1} seconds.",
dr["Lesson"].ToString(), Math.Round(diff));
}
else if (diff == 0)
{
lblMessage.Text = string.Format("{0} lession started.", dr["Lesson"].ToString());
}
}
}
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="lblMessage" runat="server" />
<asp:Timer ID="Timer1" runat="server" OnTick="TimerTick" Interval="1000" />
</ContentTemplate>
</asp:UpdatePanel>