asp.net - String was not recognized as a valid DateTime c# -


trying insert data in database it's return error , date format trying add in format example : 20/05/2015

my code :

 bool flag = gh.set_policyinfo(convert.tostring(comboxbranchname.selecteditem.text),                                "dept_06",                                txtpolicyno.text,                                convert.tostring(comboxpolicytype.selecteditem.text),                                convert.todatetime(txtpolicydate.text), convert.tostring(comboxaccnametst.text),                                convert.todouble(txtplcyamt.text), convert.todouble(txtissuefee.text),                                convert.todouble(txtsprvisionfee.text), convert.todouble(txttransfee.text),                                convert.toint32(txtdiscountper.text), convert.todouble(txtdiscountamt.text),                                convert.todouble(txttotalamt.text), convert.todouble(txtnetamt.text),                                datetime.parseexact(textstartdate.text.tostring(), "dd/mm/yyyy", cultureinfo.invariantculture),                                datetime.parseexact(txtenddate.text.tostring(), "dd/mm/yyyy", cultureinfo.invariantculture),                                'a',                                datetime.parseexact("20042012", "dd/mm/yyyy", null), "devp"); 

since using parseexact, string needs match format string exactly. means separators need there.

so see 2 options:

1. pass date using appropriate format

 bool flag = gh.set_policyinfo(convert.tostring(comboxbranchname.selecteditem.text), "dept_06", txtpolicyno.text, convert.tostring(comboxpolicytype.selecteditem.text), convert.todatetime(txtpolicydate.text), convert.tostring(comboxaccnametst.text), convert.todouble(txtplcyamt.text), convert.todouble(txtissuefee.text), convert.todouble(txtsprvisionfee.text), convert.todouble(txttransfee.text), convert.toint32(txtdiscountper.text), convert.todouble(txtdiscountamt.text), convert.todouble(txttotalamt.text), convert.todouble(txtnetamt.text),datetime.parseexact(textstartdate.text.tostring(), "dd/mm/yyyy", cultureinfo.invariantculture), datetime.parseexact(txtenddate.text.tostring(), "dd/mm/yyyy", cultureinfo.invariantculture), 'a', datetime.parseexact("20/04/2012", "dd/mm/yyyy", null), "devp"); 

2. remove separators format string

 bool flag = gh.set_policyinfo(convert.tostring(comboxbranchname.selecteditem.text), "dept_06", txtpolicyno.text, convert.tostring(comboxpolicytype.selecteditem.text), convert.todatetime(txtpolicydate.text), convert.tostring(comboxaccnametst.text), convert.todouble(txtplcyamt.text), convert.todouble(txtissuefee.text), convert.todouble(txtsprvisionfee.text), convert.todouble(txttransfee.text), convert.toint32(txtdiscountper.text), convert.todouble(txtdiscountamt.text), convert.todouble(txttotalamt.text), convert.todouble(txtnetamt.text),datetime.parseexact(textstartdate.text.tostring(), "ddmmyyyy", cultureinfo.invariantculture), datetime.parseexact(txtenddate.text.tostring(), "ddmmyyyy", cultureinfo.invariantculture), 'a', datetime.parseexact("20042012", "ddmmyyyy", null), "devp"); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -