public void insertdata(){尝试{
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。
由于要在多个位置调用同一函数,因此可以创建另一个带有insertdata()函数的类。之后,您可以在各自的表单中添加该类的引用。