我有两种形式,第一种形式有 insertdata() 这是我想提前调用付款形式我该怎么做

i have two forms, 1st Form have insertdata() which is i want to call in advancePayment Form how can i do that

public无效插入数据() { 尝试 {

            con.Open();
            OleDbCommand cmd = con.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "insert into customers(customer_name,address,email,mob_no) values('" + tname.Text + "','" + taddress.Text + "','" + temail.Text + "','" + tmobno.Text + "')";
            cmd.ExecuteNonQuery();
            MessageBox.Show("Registered Successfully");



            con.Close();
            tname.Text = "";
            taddress.Text = "";
            temail.Text = "";
            tmobno.Text = "";
        }
        catch (Exception e)
        {
            MessageBox.Show("Problem in Registering Customer,Please Enter all Fields Correctly" + e);

        }

    }

''这是我想在 button_click 上的 advancePayment 的另一个表单中调用的函数。

因为你想在多个地方调用同一个函数,你可以做的是创建另一个 class,其中包含 insertdata() 函数。之后,您可以在各自的表格中添加该 class 的引用。