database - Updating datas in another form c# -


hello guys can me problem how can update information form have 2 forms here 1 information list , want second form update list in info lists here's code form information lists

info lists(first form):

info lists(first form)

updating info (second form)

updating info (second form)

to first picture info form here's code

public partial class form3 : form {     sqlconnection con = new sqlconnection(@"data source=.\sqlexpress;attachdbfilename=c:\users\pc\documents\visual studio 2010\projects\gg\gg\database1.mdf;integrated security=true;user instance=true");     sqlcommand cmd = new sqlcommand();     sqldatareader dr;       public form3()     {         initializecomponent();     }      private void button1_click(object sender, eventargs e)     {      }      private void form3_load(object sender, eventargs e)     {         cmd.connection = con;         loadlist();     }     public void loadlist()     {         listbox1.items.clear();         listbox2.items.clear();         listbox3.items.clear();         listbox4.items.clear();         con.open();         cmd.commandtext = "select * information";         dr = cmd.executereader();         if (dr.hasrows)         {             while (dr.read())             {                  listbox1.items.add(dr[0].tostring());                 listbox2.items.add(dr[1].tostring());                 listbox3.items.add(dr[2].tostring());                 listbox4.items.add(dr[3].tostring());                 listbox5.items.add(dr[4].tostring());                 listbox6.items.add(dr[5].tostring());              }         }         con.close();     }      public void listbox4_selectedindexchanged(object sender, eventargs e)     {         listbox l = sender listbox;         if (l.selectedindex != -1)         {             listbox1.selectedindex = l.selectedindex;             listbox2.selectedindex = l.selectedindex;             listbox3.selectedindex = l.selectedindex;             listbox4.selectedindex = l.selectedindex;             listbox5.selectedindex = l.selectedindex;             listbox6.selectedindex = l.selectedindex;                        }     }      private void button1_click_1(object sender, eventargs e)     {         form2 f2 = new form2();         f2.showdialog();     }      public void button2_click(object sender, eventargs e)     {          form4 f4 = new form4();          f4.textbox1.text = listbox1.selecteditem.tostring();         f4.textbox2.text = listbox2.selecteditem.tostring();         f4.textbox3.text = listbox3.selecteditem.tostring();         f4.textbox4.text = listbox4.selecteditem.tostring();         f4.datetimepicker1.value = datetime.now;         f4.textbox5.text = listbox6.selecteditem.tostring();          f4.showdialog();     }      } 

form 2 updating in second picture

public partial class form4 : form {       static string constring = @"data source=.\sqlexpress;attachdbfilename=c:\users\pc\documents\visual studio 2010\projects\gg\gg\database1.mdf;integrated security=true;user instance=true";     sqlconnection condatabase = new sqlconnection(constring);     sqlcommand command = new sqlcommand();     datatable dt = new datatable();      form3 f3 = new form3();      public form4()     {         initializecomponent();     }      private void form4_load(object sender, eventargs e)     {         command.connection = condatabase;     }       private void button1_click(object sender, eventargs e)     {         if (textbox1.text != "" & textbox2.text != "" & textbox3.text != "" & textbox4.text != "" & textbox5.text != "")         {             condatabase.open();             command.commandtext = "update information set id='" + this.textbox1.text.tostring() +                                     "',firstname='" + this.textbox2.text.tostring() +                                     "',middlename='" + this.textbox3.text.tostring() +                                     "',lastname='" + this.textbox4.text.tostring() +                                     "',dateofbirth='" + this.datetimepicker1.value.tostring() +                                     "',placeofbirth='" + this.textbox5.text +                                     "' id='" + this.textbox1.text +                                     "',firstname='" + f3.listbox2.selecteditem.tostring() +                                     "',middlename='" + f3.listbox3.selecteditem.tostring() +                                     "',lastname='" + f3.listbox4.selecteditem.tostring() +                                     "',dateofbirth='" + f3.listbox5.selecteditem.tostring() +                                     "',placeofbirth='" + f3.listbox6.selecteditem.tostring() + "' ";             command.executenonquery();              condatabase.close();             messagebox.show("update successfull");             textbox2.clear();             textbox3.clear();             textbox4.clear();             datetimepicker1.value = datetime.now;             textbox5.clear();             f3.loadlist();         }     } } 


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -