J'ai créé un programme avec deux froms (form1, form2) .Form1 a le datagridview et le Form2 je l'utilise pour transmettre les données à la base de données (que j'ai vu dans datagridview). Je veux quand j'appuie sur le bouton de sauvegarde dans le form2 le même temps a vu les valeurs dans le datagridview à la forme1 avec hors refresh de butoon (comme cela est maintenant).Auto show change dans datagridview
Le code suivant est le bouton d'enregistrement:
string cdata = "Server=127.0.0.1;Database=liveriservis;Port=3306;Uid=root;Pwd=axmn1336;";
MySqlConnection con = new MySqlConnection(cdata);
Querypelatis = "insert into liveriservis.pelatis(Όνομα,Επώνυμο,Κινητό,Σταθερό,date) values('" + this.name.Text + "','" + this.eponimo.Text + "','" + this.kinito.Text + "','" + this.stathero.Text + "','" + this.dateTimePicker2.Text + "');";
Queryteliko = "insert into liveriservis.teliko(Date,Όνομα,Επώνυμο,Σταθερό,Κινητό,ΠρόβλημαPc,ΠρόβλημαPc1,ΜοντέλοLaptop,ΠρόβλημαLaptop,ΠρόβλημαLaptop1,ΕξαρτήματαLaptop,ΜοντέλοΚινητό,ΠρόβλημαΚινητό,ΠρόβλημαΚινητό1,Αρίθμηση,Τιμή)values ('" + this.dateTimePicker2.Text + "','" + this.name.Text + "','" + this.eponimo.Text + "','" + this.stathero.Text + "','" + this.kinito.Text + "','" + this.problimapc.Text + "','" + strpc + "','" + this.modelolaptop.Text + "','" + this.problimalaptop.Text + "','" + strlaptop + "','" + strlaptop1 + "','" + modelo + "','" + this.problimakinito.Text + "','" + strkinito + "','" + this.arithisi.Text + "','" + this.timi.Text + "') ;";
Queryolokliromeno = "insert into liveriservis.olokliromeno(Date,Όνομα,Επώνυμο,Σταθερό,Κινητό,ΠρόβλημαPc,ΠρόβλημαPc1,ΜοντέλοLaptop,ΠρόβλημαLaptop,ΠρόβλημαLaptop1,ΕξαρτήματαLaptop,ΜοντέλοΚινητό,ΠρόβλημαΚινητό,ΠρόβλημαΚινητό1,Αρίθμηση,Τιμή)values ('" + this.dateTimePicker2.Text + "','" + this.name.Text + "','" + this.eponimo.Text + "','" + this.stathero.Text + "','" + this.kinito.Text + "','" + this.problimapc.Text + "','" + strpc + "','" + this.modelolaptop.Text + "','" + this.problimalaptop.Text + "','" + strlaptop + "','" + strlaptop1 + "','" + modelo + "','" + this.problimakinito.Text + "','" + strkinito + "','" + this.arithisi.Text + "','" + this.timi.Text + "') ;";
MySqlCommand cmpelatis = new MySqlCommand(Querypelatis, con);
MySqlCommand cmteliko = new MySqlCommand(Queryteliko,con);
MySqlCommand cmolokliromeno = new MySqlCommand(Queryolokliromeno, con);
MySqlDataReader myReader;
try
{
con.Open();
myReader = cmpelatis.ExecuteReader();
con.Close();
con.Open();
myReader = cmteliko.ExecuteReader();
con.Close();
con.Open();
myReader = cmolokliromeno.ExecuteReader();
DialogResult dialog= MessageBox.Show("Saved","Saved",MessageBoxButtons.OK);
if (dialog == DialogResult.OK) { this.Close(); }
//else if (dialog == DialogResult.No) { e.Cancel = true; }
while (myReader.Read())
{
// Application.Exit();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
// Application.Exit();
}
}
Et le code suivant est le bouton d'actualisation:
string cdata = "Server=127.0.0.1;Database=liveriservis;Port=3306;Uid=root;Pwd=axmn1336;";
condata = new MySqlConnection(cdata);
cmgrid = new MySqlCommand("select * from liveriservis.teliko", condata);
sda = new MySqlDataAdapter();
sda.SelectCommand = cmgrid;
dset = new DataTable();
sda.Fill(dset);
BindingSource bSource = new BindingSource();
bSource.DataSource = dset;
dataGridView1.DataSource = bSource;
sda.Update(dset);