简体   繁体   中英

Error when adding days to date time in windows form C#

I'm trying to add a renewal system where the user can request for extra days. I've tried to layout aa method which will take the value from a combobox and then add that value in days to the current expiry date.

As can be seen in the screen shot below, I'm having an error when trying to add days onto an existing date. I tried various SqlDbTypes including datetime with no success, maybe this isn't the best way to convert the value to days in terms of SQL?

Any ideas?

在此处输入图片说明

DATEADD function takes int as a second parameter. But you try to add your @days parameter with SqlDbType.VarChar type.

Add this parameter value as an SqlDbType.Int and parse your cboDays.Text to integer. For example;

com.Parameters.Add("@days", SqlDbType.Int).Value = Int32.Parse(cboDays.Text);

Also your UserID seems like a numeric column typed since it ends with ID . In this case, VarChar type does not fit for this column.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM