方法'(函数名)'的重载没有'0'参数

时间:2013-08-16 06:28:29

标签: c# overloading

在调试时遇到了这个错误:“方法'没有重载'STUDENTCOURSEDETAILS_Load'取'0'参数”

STUDENTCOURSEDETAILS是Winform,STUDENTCOURSEDETAILS_Load是form.i的OnLoad事件,试图在另一个函数中调用此事件并得到上述错误。如何在另一个函数中调用事件?如何在调用此事件时传递参数?我不知道我必须传递哪种参数的sholud。需要帮助......

private void STUDENTCOURSEDETAILS_Load(object sender, EventArgs e)
        {
            txtregno.Enabled        = false;
            txtstudentname.Enabled  = false;
            txtcoursid.Enabled      = false;
            txtcoursname.Enabled    = false;
            dtpdoj.Enabled          = false;
            txtfee.Enabled          = false;
            txtdiscountper.Enabled  = false;
            txtnarration.Enabled    = false;
            btnSave.Text            = "&Add";

        }

private void btnAdd_Click(object sender, EventArgs e)
        {
            switch (btnSave.Text)
            {
                case "&Add":
                    txtregno.Enabled        = true;
                    txtstudentname.Enabled  = true;
                    txtcoursid.Enabled      = true;
                    txtcoursname.Enabled    = true;
                    dtpdoj.Enabled          = true;
                    txtfee.Enabled          = true;
                    txtdiscountper.Enabled  = true;
                    txtnarration.Enabled    = true;
                    btnSave.Text            = "&Save";
                    break;
                case "&Save":
                    if (validation())
                    {
                        if (MessageBox.Show("sure to save?", CPublic.messagename, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            selectstudentid();
                            cmd.Connection = CPublic.Comm_con;
                            cmd.Parameters.Clear();
                            cmd.Parameters.AddWithValue("@regno", txtregno.Text);
                            cmd.Parameters.AddWithValue("@studentid", id);
                            cmd.Parameters.AddWithValue("@studentname", txtstudentname.Text);
                            cmd.Parameters.AddWithValue("@courseid", txtcoursid.Text);
                            cmd.Parameters.AddWithValue("@coursename", txtcoursname.Text);
                            cmd.Parameters.AddWithValue("@doj", dtpdoj.Value.ToString(CGeneral.ServeDateFmt));
                            cmd.Parameters.AddWithValue("@fee", txtfee.Text);
                            cmd.Parameters.AddWithValue("@discount", txtdiscountper.Text);
                            cmd.Parameters.AddWithValue("@narration", txtnarration.Text);
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.CommandText = "SP_INSERT_studentcoursedetails" + CPublic.g_firmcode;
                            cmd.ExecuteNonQuery();
                            MessageBox.Show("COURSE ADDED SUCCESSFULLY...", CPublic.messagename, MessageBoxButtons.OK, MessageBoxIcon.Information);
                            clearall();
                            btnSave.Enabled         = true;
                            btnSave.Text            = "&Add";
                            STUDENTCOURSEDETAILS_Load();
                         }
                    }
                            break;
            }
        }

2 个答案:

答案 0 :(得分:3)

那是因为行

btnSave.Text            = "&Add";
STUDENTCOURSEDETAILS_Load();

你应该使用

STUDENTCOURSEDETAILS_Load(null, null);

显然,您可能会在运行时遇到更多错误。

答案 1 :(得分:1)

你可以这样调用这个方法:

STUDENTCOURSEDETAILS_Load(null, null);