找不到错误
本文关键字:错误 找不到 | 更新日期: 2023-09-27 17:55:39
我的程序出现错误,无法解决问题。当我尝试将用户输入分配给类中的变量时,出现了此问题。
有问题的两个变量是:Quantity_Of_Order(字符串)和Date_Of_Purchase(字符串)
使用Quantity_Of_Order,我正在尝试为其分配在文本框中输入的值。对于Date_Of_Purchase,我正在尝试为其分配在日期时间选择器中选择的值。
我尝试输出值并显示以下内容:
订单数量: 系统.Windows.Forms.文本框, 文本: 200 购买日期:System.Windows.Forms.DateTimePicker,值:01/04/2014
当我尝试使用Quantity_Of_Order时,我的程序停止工作,并收到以下消息:
mscorlib 中发生了类型为"System.FormatException"的未处理异常.dll 其他信息:输入字符串格式不正确
这是我用于获取输入并为其分配类中的变量的代码:
//This method sets the value of Quantity_Of_Order based on the amount entered by the user
void Set_Quantity_Of_Order(int identifier)
{
string quantity = txtQuantityOrdered.ToString();//txtQuantityOrdered is the text box where user enters value
Order[identifier].Quantity_Of_Order = quantity;
}
//This method sets the value of Date_Of_Purchase, based on the date entered by the user
void Set_Date_Of_Purchase(int identifier)
{
string purchase_date = dtpPurchaseDate.ToString();//dtpPurchaseDate is the date time picker where user selects date of purchase.
Order[identifier].Date_Of_Purchase = purchase_date;
}
我确定我刚刚犯了一个菜鸟错误,因为我是 C# 的新手。您能提供的任何帮助将不胜感激。
谢谢
你不应该使用txtQuantityOrdered.ToString();
而是
txtQuantityOrdered.Text
和
dtpPurchaseDate.Text
或
dtpPurchaseDate.Value
最后一个输出一个DateTime
对象。