One. Delete
1.
while(Usrlistview.selectedindex! =-1) { varCurrentselectindex =Usrlistview.selectedindex; varitem =Usrview[currentselectindex]; using(Stockmanagedatacontext Smdatacontext =NewStockmanagedatacontext ()) { Try{Smdatacontext.executecommand ("DELETE from USERS WHERE id={0}", item.id); Usrview.removeat (Currentselectindex); } Catch(Exception ex) {MessageBox.Show (ex). Message); } } }
2.
Private voidMenuitemdelete_click (Objectsender, RoutedEventArgs e) { if(Addresslist.selectedindex = =-1) {MessageBox.Show ("Please select an item!"); return; } if(MessageBox.Show ("confirm that the selected vendor information is deleted? ","Tips", messageboxbutton.okcancel) = =Messageboxresult.ok) { while(Addresslist.selectedindex! =-1){ varCurrentselectindex =Addresslist.selectedindex; SHDZ selectedaddress=(SHDZ) Addresslist.selectedvalue; using(Wjkcdatacontext WJKC =NewWjkcdatacontext ()) { Try{WJKC. ExecuteCommand ("DELETE from Shdz WHERE code={0}", Selectedaddress.code); Addressview.removeat (Currentselectindex); } Catch(Exception ex) {MessageBox.Show (ex). Message); } } return; } } } }
Two. Insert
1.
Try { using(Stockmanagedatacontext Smdatacontext =NewStockmanagedatacontext ()) {SmDataContext.Users.InsertOnSubmit (NewUser {UserName = usrname.text, Password = pwd, Permission =permissionlevel}); Smdatacontext.submitchanges (); MessageBox.Show ("Add user to change success! "); Usrview.clear (); GetData (); Usrname.isenabled=false; Passwordbox1.isenabled=false; Passwordbox2.isenabled=false; Permimissionlevels.isenabled=false; Button1. IsEnabled=false; Usrname.text=string. Empty; Passwordbox1.password=string. Empty; Passwordbox2.password=string. Empty; Permimissionlevels.selectedindex=0; } }
2.
Try{WJKC. ExecuteCommand ("INSERT INTO SHDZ (code,dz,detail,isty) VALUES ({0},{1},{2},{3})", Code, TxtAName.Text.Trim (), TxtADetails.Text.Trim (), address. Isty); Lablemsg.content="Information added successfully! "; Lablemsg.foreground=NewSolidColorBrush (Color.fromrgb (0,0,255)); Clearcontrols (); Winparent.close (); //Addressinfowindow win = new Addressinfowindow (); //win. Show (); }
Three editors
1.
Make sure that the object you are editing is the selected object, so pass in the parameters and populate the controls first.
Try{WJKC. ExecuteCommand ("update SHDZ set detail={0},dz={1},isty={2} where code={3};", TxtADetails.Text.Trim (), TxtAName.Text.Trim (), address. Isty,address. CODE); Lblmsg.content="Information modified successfully! "; Lblmsg.foreground=NewSolidColorBrush (Color.fromrgb (0,0,255)); //This . Window_closed (); This. Close (); } Catch(Exception ex) {MessageBox.Show (ex). Message); }
2,.
Try { using(Stockmanagedatacontext Smdatacontext =NewStockmanagedatacontext ()) { stringUsrname = ( This. Parent asLoginwindow). User; vars = smDataContext.Users.Single (c = C.username = =usrname); S.password=pwd; Smdatacontext.submitchanges (); MessageBox.Show ("Password added successfully! "); This. Navigationservice.navigate (NewUri ("Loginpage.xaml", urikind.relative)); } } Catch(Exception ex) {MessageBox.Show (ex). Message); Label_warning. Content="Hint: password modification failed! "; }
C # Delete, insert, modify index selected entries from the database