我有一个名为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)
{
}
答案 0 :(得分:1)
你必须像这样调用你的方法:
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