سؤال

I have a function that name is Mymethod. It has three paramaters. I want to call it in Page_Load(): My question is what i should write to call MyMethod function with parameters.

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

} 
هل كانت مفيدة؟

المحلول

You must call your method like this:

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

When you call a method you don't have to write the type of the parameter. Just write the name of the variable who has the same type as the parameter.in your cas string

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top