C# 方法'没有重载;(功能名称)和#x27;采取';0';论据
调试时出现以下错误:“方法'StudentCoursedDetails\u Load'的重载不接受'0'参数” StudentCoursedDetails是Winform,StudentCoursedDetails\u Load是窗体的OnLoad事件。我试图在另一个函数中调用此事件,但出现上述错误。如何在另一个函数中调用事件?调用此事件时如何传递参数?我不知道必须传递哪种类型的参数。需要帮助C# 方法'没有重载;(功能名称)和#x27;采取';0';论据,c#,overloading,C#,Overloading,调试时出现以下错误:“方法'StudentCoursedDetails\u Load'的重载不接受'0'参数” StudentCoursedDetails是Winform,StudentCoursedDetails\u Load是窗体的OnLoad事件。我试图在另一个函数中调用此事件,但出现上述错误。如何在另一个函数中调用事件?调用此事件时如何传递参数?我不知道必须传递哪种类型的参数。需要帮助 private void STUDENTCOURSEDETAILS_Load(object sende
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;
}
}
那是因为那条线
btnSave.Text = "&Add";
STUDENTCOURSEDETAILS_Load();
你应该使用
STUDENTCOURSEDETAILS_Load(null, null);
显然,在运行时可能会遇到进一步的错误。这是因为行
btnSave.Text = "&Add";
STUDENTCOURSEDETAILS_Load();
你应该使用
STUDENTCOURSEDETAILS_Load(null, null);
显然,在运行时可能会遇到进一步的错误。您可以这样调用该方法:
STUDENTCOURSEDETAILS_Load(null, null);
您可以这样调用该方法:
STUDENTCOURSEDETAILS_Load(null, null);
将
STUDENTCOURSEDETAILS\u Load
中的代码移动到另一个方法,并在STUDENTCOURSEDETAILS\u Load
和btnAdd\u单击中调用它,然后将STUDENTCOURSEDETAILS\u Load
中的代码移动到另一个方法,并在STUDENTCOURSEDETAILS\u Load
和btnAdd\u单击中调用它,谢谢@Nisarg沙阿。不管怎样,它都工作得很好,并期待您指定的运行时错误。那么,完成这项任务的正确方法是什么呢???请说明您遇到的错误。因为准确的错误将帮助我解决您的错误“StudentCoursedDetails\u Load”方法的重载不接受“0”参数“这是我以前得到的,而不是现在。是的,这就是解决方案的目的。那么现在您还想要什么呢?您已经提到“可能会在运行时遇到进一步的错误”“所以我在问如何避免运行时错误?谢谢@Nisarg Shah。不管怎样,它都工作得很好,并期待您指定的运行时错误。那么,完成这项任务的正确方法是什么呢???请说明您遇到的错误。因为准确的错误将帮助我解决您的错误“StudentCoursedDetails\u Load”方法的重载不接受“0”参数“这是我以前得到的,而不是现在。是的,这就是解决方案的目的。那么现在您还想要什么呢?您已经提到“可能会在运行时遇到进一步的错误”“所以我在问如何避免运行时错误?