繁体   English   中英

在C#中传递datetime参数

[英]passing datetime parameters in C#

我的以下代码是将客户详细信息添加到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);

我在“值”下显示红线-状态为“;预期”

以及Customers(在新版本之后)-声明“没有给出与Customers.Customers的必需形式参数“ birthdate”相对应的参数(int,int,string,string,string,string,string,string,int,DateTime) ”“。

我不确定要解决此问题需要做什么。 生日是客户类中的DateTime格式。

任何帮助,将不胜感激。

好像您在第二个参数lbCategoryID.Item[cbCategory.SelectedIndex].ToString(),中发送字符串lbCategoryID.Item[cbCategory.SelectedIndex].ToString(),并且通过错误消息,您应该发送整数。

您可以尝试以下方法:

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

至于特定的错误:在int.Parse(txtPostcode.Text).ToString())之后删除流浪括号。 编译器正确地认为该语句应在此处结束,但随后缺少分号。

之后,您将不得不处理所有其他错误:显然,构造函数在前两个参数中需要两个int 您没有提供两个int ,但是第二个参数是string

另外,您没有为邮政编码提供int值。

因此,所有参数中的所有参数根本与所需的类型都不匹配。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM