0
我的任務是,每個月,藥物表中的數量列將更新到當前月份的報告表中的列。我想在不使用任務調度程序的情況下執行此操作。我在線研究了線程和計時器。但是,我不確定它是否可以工作,因爲線程將每月自動更新同一列。正如你所看到的,我需要每個月更新不同的列。我試圖自動填充每月使用asp.net的報告#
這裏是我的代碼:
DateTime today = DateTime.Today;
DateTime firstDay = new DateTime(today.Year, today.Month, 1);
if (today == firstDay)
{
while (true)
{
string sql1 = "SELECT quantity FROM medicine";
DataSet ds = DBMgr.GetDataSet(sql1);
int quantity = int.Parse(ds.Tables[0].Rows[0]["quantity"].ToString());
string month = DateTime.Now.ToString("MMMM");
if (month.Equals("January"))
{
string sql = "UPDATE report SET Jan = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("February"))
{
string sql = "UPDATE report SET Feb = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("March"))
{
string sql = "UPDATE report SET Mar = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("April"))
{
string sql = "UPDATE report SET Apr = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("May"))
{
string sql = "UPDATE report SET May = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("June"))
{
string sql = "UPDATE report SET June = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("July"))
{
string sql = "UPDATE report SET July = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("August"))
{
string sql = "UPDATE report SET Aug = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("September"))
{
string sql = "UPDATE report SET Sep = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("October"))
{
string sql = "UPDATE report SET Oct = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("November"))
{
string sql = "UPDATE report SET Nov = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
if (month.Equals("December"))
{
string sql = "UPDATE report SET Dec = '{0}'";
DBMgr.ExecuteSQL(sql, quantity);
}
else
{
LblMsg.Text = "An Error Occurred";
}
}
當月的列並沒有被更新的。提前致謝!
separatelly檢查,如果我重新安排代碼有一段時間(真)作爲第一個代碼,頁面上會只是繼續刷新。有沒有辦法阻止while(true)循環? – Hamira
你可以停止'while(true)'循環返回或中斷請參閱http://www.c-sharpcorner.com/UploadFile/2072a9/break-and-continue-statements-in-C-Sharp/ – ASpirin