C# 如何对具有参数的主类调用函数?

C# 如何对具有参数的主类调用函数?,c#,function,parameters,C#,Function,Parameters,我有一个函数名为Mymethod。它有三个参数。我想在Page_Load()中调用它: 我的问题是我应该写什么来调用带有参数的MyMethod函数 public static string MyMethod(string Pro_id, string Sta_id, string Ity_id) { try { MySqlConnection con = new MySqlConnection(Globals.CONNECTION_STRING);

我有一个函数名为Mymethod。它有三个参数。我想在Page_Load()中调用它:
我的问题是我应该写什么来调用带有参数的MyMethod函数

public static string MyMethod(string Pro_id, string Sta_id, string Ity_id)
{
    try
    {
        MySqlConnection con = new MySqlConnection(Globals.CONNECTION_STRING);
        con.Open();
        String UserId = HttpContext.Current.Session["user_id"].ToString();

        MySqlCommand cmd = new MySqlCommand("INSERT INTO issue values ('" + UserId + "','" + Pro_id + "','" + Sta_id + "','" + Ity_id + "')", con);
        cmd.ExecuteNonQuery();
        con.Close();
    }
    catch (Exception err)
    {
        return "error";
    }
    return "success";
}

protected void Page_Load(object sender, EventArgs e)
{

} 

您必须像这样调用您的方法:

 protected void Page_Load(object sender, EventArgs e)
 {
   string pro_id="xxx";//you need to assign it or retrieve somewhere
   string sta_id="xxx";//you need to assign it or retrieve somewhere
   string ity_id="xxx";//you need to assign it or retrieve somewhere

  MyMethod(pro_id, sta_id, ity_id);
 } 

调用方法时,不必写入参数的类型。只需写下与参数类型相同的变量的名称。在您的cas
string

中,问题是什么?我在加载页面中写了“MyMethod(string Pro_id,string Sta_id,string icity_id)”,但我有错误。您遇到了什么错误。。我的问题是我应该写什么来调用带有参数的MyMethod函数。我们的问题是你会遇到什么错误