我有以下代码,是将客户详细信息添加到Windows窗体并将数据传输到SQL的总体代码的一部分。我只是编码的新手,我不确定如何解决以下错误:
Customers customer = new Customers(GlobalVariables.selectedCustomerID,
lbCategoryID.Item[cbCategory.SelectedIndex].ToString(),
txtFirstName.Text, txtLastName.Text, cbGender.Text,
txtAddress.Text,
txtSuburb.Text, cbState.Text,
int.Parse(txtPostcode.Text).ToString()), dtpBirthdate.Value);
我在“值”下显示一条红线-状态为“;预期”
以及“客户”(新用户之后)-声明“没有给出与客户所需的形式参数“生日”相对应的参数。客户(int,int,string,string,string,string,string,string,int ,DateTime)'。”
我不确定该如何解决。生日是客户类中的DateTime格式。
任何帮助将不胜感激。
答案 0 :(得分:0)
您可以共享Customers类的构造函数吗?看起来您在第二个参数lbCategoryID.Item[cbCategory.SelectedIndex].ToString(),
中发送了一个字符串,并且错误消息提示您应该发送整数。
答案 1 :(得分:0)
您可以尝试以下方法:
Customers customer = new Customers(GlobalVariables.selectedCustomerID, lbCategoryID.Item[cbCategory.SelectedIndex], txtFirstName.Text, txtLastName.Text, cbGender.Text, txtAddress.Text, txtSuburb.Text, cbState.Text, int.Parse(txtPostcode.Text), dtpBirthdate.Value);
已删除了int.Parse(txtPostcode.Text)和lbCategoryID.Item [cbCategory.SelectedIndex];额外的.ToString();
答案 2 :(得分:0)
关于特定错误:在int.Parse(txtPostcode.Text).ToString())
之后卸下流浪括号。编译器正确地认为该语句应在此处结束,但随后缺少分号。
之后,您将不得不处理所有其他错误:
显然,构造函数在前两个参数中需要两个int
。您没有提供两个int
,但是第二个参数是string
。
此外,您没有为邮政编码提供int
。
因此,您所有参数中的所有参数根本与所需的类型都不匹配。