父窗体Form1 子窗体Form2 Form1中有一个datagridview控件和一添加按钮,
Form2中有一个Text控件和一个保存按钮 要求点击Form1窗体上的添加按钮,弹出Form2,
再text里面输入内容,点击保存自动关闭Form2,刷新Form1中datagridview中的数据

From1中:

private void button3_Click(object sender, EventArgs e)
        {
            Form2 f2 = new Form2();
            f2.ShowDialog();
            if (f2.DialogResult == DialogResult.OK)
            {
                this.datagridBind();//重新绑定
            }
            
        }

From2中:


private void button1_Click(object sender, EventArgs e) { string strConn = "server=.;database=filesSync;uid=sa;pwd=123"; SqlConnection conn = new SqlConnection(strConn); string sql = "insert into asyncFileList values ('" + textBox1.Text.ToString() + "')"; conn.Open(); SqlCommand myCmd = new SqlCommand(sql, conn); myCmd.ExecuteNonQuery(); conn.Close(); this.DialogResult = DialogResult.OK; MessageBox.Show("添加成功"); this.Close(); }

  

相关文章:

  • 2021-09-23
  • 2022-12-23
  • 2021-11-02
  • 2021-10-10
  • 2021-11-28
  • 2021-12-15
猜你喜欢
  • 2021-10-03
  • 2022-12-23
  • 2021-12-21
  • 2021-09-13
  • 2022-12-23
  • 2021-10-04
  • 2022-03-09
相关资源
相似解决方案