私は2つのfroms(form1、form2)で1つのプログラムを作成しました.Form1にはdatagridviewがあり、Form2はデータをデータベースに渡します(datagridviewで見た)。私は私がフォーム2の保存ボタンを押したときに、同じように、現在のように、リフレッシュバウンスを外してform1でdatagridviewの値を見たかった。DataGridviewのオートショーの変更
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();
}
}
、次のコードは、リフレッシュボタンです:
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);