winforms - input string was not in a correct format [C#] -
i have application automatically generates order id. want 9999-99-9999, first 4 numbers represents year. now, second 1 month , last auto-incremented.
i'm working on second 1 month. in code have know whether 2 digit number or 1 digit number can add zero. when run application there error says input string not in correct format. mean? there error in code?
private void btnok_click(object sender, eventargs e) { string order_id = datetime.now.year.tostring(); order_id += "-"; if (convert.toint32(order_id) < 10) { order_id += "0"; } order_id += datetime.now.month.tostring(); } the error in line convert.toint32(order_id).
seems program has failed converting order_id integer because contains - ,
you don't need use :
string order_id = datetime.now.tostring("yyyy-mm");
Comments
Post a Comment