Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 所选日期=所选数据的名称不存在_C#_Asp.net_Calendar - Fatal编程技术网

C# 所选日期=所选数据的名称不存在

C# 所选日期=所选数据的名称不存在,c#,asp.net,calendar,C#,Asp.net,Calendar,我正在创建一个asp.net应用程序,并使用了以下代码: Application["getData"] = new GigOpportunity(txtId.Text, Convert.ToDateTime(SelectedData), txtVenue.Text,

我正在创建一个asp.net应用程序,并使用了以下代码:

Application["getData"] = new GigOpportunity(txtId.Text, 
                                            Convert.ToDateTime(SelectedData),
                                            txtVenue.Text, 
                                            txtGenre.Text, 
                                            Convert.ToDouble(txtCost.Text), 
                                            Convert.ToInt32(txtCapacity.Text), 
                                            chkHeadliner.Checked, 
                                            txtMainAct.Text, 
                                            chkEngineer.Checked);
但当我运行表单并选择OK时,它会显示:

输入字符串的格式不正确

当我进一步查看selecteddata变量时,它会说:

SelectedDate=当前上下文中不存在名称“SelectedData”


这就是SelectedData的来源:

string SelectedData = dateTimePicker.SelectedDate.ToString("dd MMMM yyyy"); 

如果您已经有了日期时间,为什么不直接使用它并将其传递给GigOpportunity

新信息后编辑

您得到的错误通常是由于使用了一个尚未声明的变量引起的。 我相信GigOpportunity的构造器有一个错误。检查构造函数并查看参数名称是否正确

我想说,在构造函数中,参数是selecteddate 当它被设定时,它说

 this.selecteddate = selecteddata
应该说

this.selecteddate = selecteddate

是Convert.ToDateTimeSelectedData还是Convert.ToDateTimeSelectedDate?这就是SelectedDate的来源:string SelectedData=dateTimePicker.SelectedDate.ToString MMM MM yyyy;你仍然没有正确回答我的问题!是“SelectedData”还是“SelectedDate”?很抱歉,是的,它是SelectedData。请尝试DateTime.Parse方法而不是Convert.ToDateTime方法,因为它应该与其他所有内容一起发送,我不想将所有内容单独传递,尽管我想我可以这样做,但似乎这种方式也应该可以;您是否使用了调试器来查看它是在设置SelectedData时中断的,还是在GigOpportunity构造函数中转换时中断的。另外,您是否可以向我们展示完整的方法以及表单中声明datepicker的部分?转换时的datepicker是在我使用调试器时中断的。