我想在按钮被点击的当月插入24个月......我该怎么办? [英] I Want To Insert 24 Month From Current Month When Button Is Click...... How Can I Do ?

查看:50
本文介绍了我想在按钮被点击的当月插入24个月......我该怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

int Month = DateTime.Now.Month - 1;

for (int i = Month; i <= 11; i++)
{
   Month++;
   using (DataTableAdapters.AttendanceRegisterTableAdapter Reg = new RRHFOEM04.DataTableAdapters.AttendanceRegisterTableAdapter())
   {
      Reg.AttendanceRegister_Insert(txtStudentID.Text, Convert.ToString(DateTime.Now.Hour + ":" + DateTime.Now.Minute), Convert.ToString(Month), "2014", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "");
   }
}





以上代码仅插入当前年份...但我想插入下一个从当月起24个月



Above code are insert only current year month... but i want to insert next 24 month from current month

推荐答案

尝试:

Try:
DateTime now = DateTime.Now;
int Month = now.Month - 1;
DateTime twoYearsAhead = now.AddMonths(24);
...

然后保存该值。



(最好只在需要时读取当前时间一次它会导致间歇性的奇怪错误,如果日期或时间在提取之间发生变化则非常难以追踪,例如在每分钟结束时发生。

Then save that value.

(It's a good idea to only read the current time once when you need it, or it can cause intermittent odd errors which are very difficult to track down if the date or time changes between fetches, as happens at the end of each minute for example.


这篇关于我想在按钮被点击的当月插入24个月......我该怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆