簡體   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