public class RegistrationClass
{
SqlConnection myConnection = new SqlConnection("Data Source=MOE-PC\\SQLEXPRESS;Initial Catalog=db_University;Integrated Security=True;Pooling=False");
ConnectionClass con = new ConnectionClass();
int ID , i;
String fullName, motherName, gender, placeOfBirth, email, phone, adress, schoolDegree, languages, highSchool, faculty, major;
public void setValues (String fullName1,String motherName1,String gender1,String placeOfBirth1,String email1,String phone1,String adress1, String faculty1,String major1,String schoolDegree1,String languages1,String highSchool1)
{
fullName = fullName1;
motherName = motherName1;
gender = gender1;
placeOfBirth= placeOfBirth1;
email =email1;
phone= phone1;
adress =adress1;
faculty =faculty1;
major =major1;
schoolDegree =schoolDegree1;
languages =languages1;
highSchool = highSchool1;
}
这是注册按钮上的webform单击
public partial class WebForm1 : System.Web.UI.Page
{
protected void Button_Register_Click(object sender, EventArgs e)
{
string lang = "";
Classes.RegistrationClass R = new Classes.RegistrationClass();
R.setValues(txt_Name.ToString, txt_MotherName.ToString, dropDown_Gender.ToString, dropDown_POB.ToString, txt_Email.ToString, txt_Phone.ToString, txt_Adress.ToString, DropDown_Faculty.ToString, DropDown_Major.ToString, dropDown_SchoolDegree.ToString, txt_Name.ToString, txt_HighSchool.ToString);
。 。 。
这是错误:
'CCharpApp.RegistrationClass.setValues(string,string,string,string,string,string,string,string,string,string,string,string)'的最佳重载方法匹配'有一些无效的参数。
请帮帮我。
答案 0 :(得分:14)
txt_Name.ToString
解析为引用ToString
方法的方法组。它不会调用 ToString
。要做到这一点,你需要写txt_Name.ToString()
。话虽如此,你也不想这样做。 ToString
的{{1}}方法不会返回控件的文本。 TextBox
属性是您获取文本的方式,因此您需要编写:Text
。
最后,你应该避免使用这么多参数的函数。当你有这么多论点时遇到的错误时,试图确定错误是多么困难;它有很多方法可以关闭。相反,txt_Name.Text
应该只具有每个值的属性,然后调用者可以单独设置每个属性。这将更容易使用。
答案 1 :(得分:0)
当将dynamic
变量作为参数传递给方法时,也会发生这种情况。编译器编译没有错误,可能存在执行错误。