我需要在达到当前日期时增加文本框值 [英] I need to increase the textbox value when current date is reached

查看:85
本文介绍了我需要在达到当前日期时增加文本框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在达到当前日期时增加文本框值...

i有一个查询它完全有效,但我不知道在哪里使用它,因为当我在按钮上使用此查询时。 ...当我点击那个按钮时它总是增加价值..我只需要增加一次......请帮助



我试过的:



i need to increase the textbox value when current date is reached...
i have a query it perfectly works but i dont know where is use it because when i am using this query on button....it always increase the value when i hit that button..i need to increase only one time...please help

What I have tried:

DataTable ds = new DataTable();
            DataTable dt = new DataTable();
            cmd = new SqlCommand("select * from Lease_Management ", con);

            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);

            foreach (DataRow x in ds.Rows)
            {
                string Property_ID = x["Property_ID"].ToString();
                string Rate_of_Rent_Increament = x["Rate_of_Rent_Increament"].ToString();
                string Monthly_Rent = x["Monthly_Rent"].ToString();
                string Date_of_Rent_Renewal = x["Date_of_Rent_Renewal"].ToString();
                if (DateTime.Now.Date > DateTime.Parse(x["Date_of_Rent_Renewal"].ToString()))
                {

                    cmd = new SqlCommand("update Lease_Management set Monthly_Rent=Monthly_Rent/100*Rate_of_Rent_Increament + Monthly_Rent  where Property_ID='" + Property_ID + "'", con);
                    con.Open();
                    cmd.ExecuteNonQuery();


                }

                con.Close();
            }

推荐答案

问题是当你进行UPDATE时,你不要改变数据库来表明你做到了。而且由于DateTime.Now总是比上次调用时更大,一旦你的 if 条件为真,它将永远为真。您需要做的是添加到UPDATE以更改 Date_of_Rent_Renewal ,无论您使用何种时间来增加租金:

The problem is that when you do the UPDATE, you don't alter the database to indicate that you have done it. And since DateTime.Now is always greater than it was teh last time you called it, once your if condition is true, it will always be true. What you need to do is add to the UPDATE to alter the Date_of_Rent_Renewal by whatever period you are using to increase the rents:
UPDATE Lease_Management SET Monthly_Rent=Monthly_Rent/100*Rate_of_Rent_Increament + Monthly_Rent, Date_of_Rent_Renewal = DATEADD(yy, 1, Date_of_Rent_Renewal) WHERE Property_ID=...

将使其成为年度。


我尝试了你的代码,但仍然存在同样的问题..

总是在按下按钮时增加月租...
i tried your code but still same issue..
always increase the monthly rent when i hit on button...

这篇关于我需要在达到当前日期时增加文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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