c# - help inserting new row into a db using linq -


here snippet of code:

else     {         subcategory subcat = new subcategory         {             subcategoryname = name,             active = false,             categoryid=convert.toint32(ddlcategory.selectedvalue)         };         db.subcategories.insertonsubmit(subcat);     }      db.submitchanges(); 

the following line causing error:

categoryid=convert.toint32(ddlcategory.selectedvalue) 

i have confirmed selectedvalue in ddl int, , database expecting int, don't understand why asp.net gives me ysod saying "input string not in correct format."

if assign categoryid number manually, works.

edit: problem because populating drop down list in code behind , didn't wrap in (!ispostback). destroying list, repopulating , setting index @ 0 each time on post back.

so try then

else     {         int cat = convert.toint32(ddlcategory.selectedvalue);         subcategory subcat = new subcategory         {             subcategoryname = name,             active = false,             categoryid = cat         };         db.subcategories.insertonsubmit(subcat);     } 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -