SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["mycon"].ToString());
string sql = "select DISTINCT id,MAX(enddate) as enddate from table1 group by id";
SqlCommand cmd = new SqlCommand(sql, con);
string d1 = DateTime.Now.ToString("dd/m/yyyy");
DateTime datenow = new DateTime();
datenow = Convert.ToDateTime(d1);
DateTime enddate = new DateTime();
enddate = Convert.ToDateTime(cmd.ExecuteScalar());
if (DateTime.Compare(datenow, enddate) > 0)
{
string sql1 = "update users set type='Suspended Users' where users.id in(select DISTINCT id from table1 where enddate ='" + enddate + "')";
SqlCommand cmd1 = new SqlCommand(sql1, con);
cmd1.ExecuteNonQuery();
for (int i = 1; i < 5; i++)
{
int period = 1;
string sql2 = "update table3 set period='" + period + "'";
SqlCommand cmd2 = new SqlCommand(sql2, con);
cmd2.ExecuteNonQuery();
period++;
}my tables are
table1:
id|enddate
______________
user table:
tableid|type|id
___________________
table3:
pid|period|id
______________
1 |1 |1
2 |2 |1
3 |1 |2
4 |3 |1
5 |2 |2
