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

11 Views Asked by At

public void insertdata() { try {

            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);

        }

    }

''This is is function which i want to call in another Form which is advancePayment on button_click.

1

There are 1 best solutions below

0
On BEST ANSWER

As you want to call the same function at multiple places, what you can do is create another class with insertdata() function in it. After that, you can add reference of that class in your respective forms.