日期:2014-05-18 浏览次数:20744 次
private void button1_Click(object sender, EventArgs e) { if (this.textBox1.Text != "" && this.textBox2.Text != "" && this.textBox3.Text != "" && this.textBox4.Text != "") { try { conn = new SqlConnection("server=.;database=pangoo;uid=sa;pwd=drinker;Asynchronous Processing=True;"); conn.Open(); string cmdInsert = string.Empty; cmdInsert = "insert into users(userid,username,department,password,create_time) "; cmdInsert += " values('" + this.textBox1.Text + "'"; cmdInsert += ",'" + this.textBox2.Text + "'"; cmdInsert += ",'" + this.textBox3.Text + "'"; cmdInsert += ",'" + this.textBox4.Text + "'"; cmdInsert += ",getdate())"; SqlCommand cminsert = new SqlCommand(cmdInsert, conn); cminsert.ExecuteNonQuery(); this.Hide(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("不允许存在空格!"); } //form3里面的button1事件实现刷新winform4的datagridview。 //如今存在问题是,点击button1刷新不了已打开的那个form3中的datagridview。 Form3 fm3 = new Form3(); fm3.button1_Click(null, null); }
foreach (Form frm in Application.OpenForms) { if (frm.Name == "Form3") { //把更新的数据导入到datatable中传给Form3 frm.Update(datatable); frm.Show(); break; } }
------解决方案--------------------
看这个吧,http://www.cnblogs.com/ysh2012/archive/2012/07/28/2612807.html