c# - Import ForeignKey values by ComboBox -


i'm trying import foreignkey values using combobox, combobox loads string values , foreignkey type int,i tried convert tostring(),then got error:

"the left hand side of assignment must variable property or indexer"

            shippingdocumentdataclassesdatacontext dc = new shippingdocumentdataclassesdatacontext();         t_tracking newinvoice = new t_tracking();          newinvoice.supplierid.tostring() = combobox1.text;          dc.t_trackings.insertonsubmit(newinvoice);         dc.submitchanges(); 

any appreciated.

this line wrong:

newinvoice.supplierid.tostring() = combobox1.text; 

you trying assign value method call.

instead line should be:

newinvoice.supplierid = int32.parse(combobox1.text); 

or safer way:

int id = 0;  if (int32.tryparse(combobox1.text, out id)) {     //we valid integer combobox     newinvoice.supplierid = id;      dc.t_trackings.insertonsubmit(newinvoice);     dc.submitchanges(); } else {     //wrong value handling code goes here } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -