c# - save row in one table to another table using linq -
c# - save row in one table to another table using linq -
you know when drag , drop table datasources window onto usercontrol? visual studio automatically creates datacontext (in view's xaml) bind new elements on page to.this datacontext set collectionviewsource , collectionviewsource draws it's info dataset. same dataset took table when draging , dropping.
in scenario created:
<usercontrol.resources> <collectionviewsource x:key="signupsviewsource" source="{binding signups, source={staticresource myappndataset}}/> </usercontrol.resources> <grid datacontext="{staticresource signupsviewsource}"> <textbox x:name="idtextbox" text="{binding id, mode=twoway, notifyonvalidationerror=true, validatesonexceptions=true, updatesourcetrigger=propertychanged}"/> <textbox x:name="firstnametextbox" text="{binding firstname, mode=twoway, notifyonvalidationerror=true, validatesonexceptions=true, updatesourcetrigger=propertychanged}"/> <textbox x:name="surnametextbox" text="{binding surname, mode=twoway, notifyonvalidationerror=true, validatesonexceptions=true, updatesourcetrigger=propertychanged}"/> <textbox x:name="usernametextbox" text="{binding username, mode=twoway, notifyonvalidationerror=true, validatesonexceptions=true, updatesourcetrigger=propertychanged}"/> <textbox x:name="passwordtextbox" text="{binding password, mode=twoway, notifyonvalidationerror=true, validatesonexceptions=true, updatesourcetrigger=propertychanged}"/> </grid>
it's supposed simple signup page administrator can utilize approve , deny registrations made scrolling through, clicking approve button or clicking reject button.
the thing i'm using mvvm pattern. means properties textboxes above bound to, in collectionviewsource class, problem begins.
i need save same info 'signups' table, users table.
since properties textboxes bound in collectionviewsource, there way fetch values there? i looked through solution explorer , did not find actual class called signupviewsource. if doesn't exist, how referenced , why called class? is place holder until create own collectionviewsource class? more feasible way?what i've tried far next method supposed save info signups table users table:
private object savecurrent_commandexecute(object param) { myappentities context = new myappentities(); myapp.signup signup = new signup(); seek { myapp.user user = new medcare2.user { firstname = signup.first, surname = signup.last, username = signup.username, password = signup.password, }; // persist changes database context.users.add(user); context.savechanges(); messagebox.show("saved"); } grab (exception ex) { messagebox.show(ex.message); } }
the problem above method creates new instance of signups class i'm saving from, info in properties i'm grabbing empty. validation errors. basically. help much appreciated.
you need pass selected signup
object commandparameter
on whatever command invoking savecurrent
command. can cast object param
signup
, extract values there.
c# wpf xaml mvvm
Comments
Post a Comment