C # Delete, insert, modify index selected entries from the database

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.