I have a table column as status(Varchar,records "Paid"/"Unpaid" only) and another column as nextDateOfPay(datetime, records a date).I need to update this status column as Unpaid for the records which are as Paid when the date(present date) is passed the date in nextDateOdPay column.And I need to repeat this update for every row in the table. Primary key is Id column(integer). I have no clue where to start,do i need to use T-sql or if i have to use sql agent job.I'd like to know if there is a simple solution that i can write in the program itself.Thank you so much in advance ! Code so far is as,
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);
}