1
我有一個表列作爲狀態(Varchar,記錄「Paid」/「Unpaid」只)和另一列作爲nextDateOfPay(日期時間,記錄日期).I當日期(當前日期)在nextDateOdPay列中傳遞日期時,需要將此狀態列更新爲Unpaid作爲Paid的記錄。並且我需要爲表中的每一行重複此更新。主鍵是Id列(整數)。 我不知道從哪裏開始,我是否需要使用T-sql或者如果我必須使用SQL代理作業。我想知道是否有一個簡單的解決方案,我可以在程序本身編寫。謝謝提前太多了! 到目前爲止的代碼是,如何更新數據庫列比較日期後檢查條件C#
dateTimePicker3.Value = DateTime.Now;
textBox12.Enabled = false;
string newstat;
string query = "select Id,nextDateOfPay from gymTb where status='Paid'";
SqlConnection cn = new SqlConnection(cs);
SqlCommand cmd = new SqlCommand(query, cn);
DateTime x = DateTime.Now;
DateTime y;
if (cn.State.ToString() == "Closed")
{
cn.Open();
}
try
{
object dtx = cmd.ExecuteScalar();
y = Convert.ToDateTime(dtx);
int result = DateTime.Compare(x, y);
if (result >= 0)
newstat = "Unpaid";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
哦,我的上帝先生,我在眼淚!它的作品和這樣一個簡單的輝煌解決方案先生,太謝謝了!上帝祝福你 !!再次感謝你百萬次! – angels65
簡單的力量! –