Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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# DateTimePicker.MinDate问题_C#_Sqlite_Datetime - Fatal编程技术网

C# DateTimePicker.MinDate问题

C# DateTimePicker.MinDate问题,c#,sqlite,datetime,C#,Sqlite,Datetime,我想在VS2015中的DateTimePicker上设置最小和最大日期。我想将最小日期设置为数据库中的值,将最大日期设置为DateTime.Now。我有以下代码: SQLiteCommand cmdForShopRegDate = new SQLiteCommand(@"select Date from [ShopRegistration]", con); SQLiteDataAdapter AdapterShopRegDate = new SQLiteDataAdapter(cmdForSho

我想在
VS2015
中的
DateTimePicker
上设置最小和最大日期。我想将最小日期设置为数据库中的值,将最大日期设置为
DateTime.Now
。我有以下代码:

SQLiteCommand cmdForShopRegDate = new SQLiteCommand(@"select Date from [ShopRegistration]", con);
SQLiteDataAdapter AdapterShopRegDate = new SQLiteDataAdapter(cmdForShopRegDate);
DataTable TableShopRegDate = new DataTable();
AdapterShopRegDate.Fill(TableShopRegDate);
this.dateTimePickerStartReport.MaxDate = System.DateTime.Now.Date;
this.dateTimePickerStartReport.MinDate = Convert.ToDateTime(TableShopRegDate.Rows[0][0].ToString());
我得到以下错误:

“18-Jul-28 12:00:00 AM”的值对“MinDate”无效MinDate'必须小于MaxDate


你的问题不是很详细,似乎你在要求别人为你工作。尽管这可能是一次学习经历,但请仔细阅读一个问题

您遇到的问题与数据的格式有关。您正在分析
18-Jul-28
的值。问题是这被解析为
7/18/2028
,它肯定比
8/2/2018
大。要解决此问题,您需要使用以下格式进行分析:

yy-MMM-dd
除此之外,还可以简化代码(除非您绝对需要
DataTable
SqlLiteCommand.ExecuteScalar
返回结果集中第一行的第一列,并忽略所有其他数据

using (SqlLiteConnection conn = new SqlLiteConnection("put your connection string here")) {
    using (SqlLiteCommand cmd = new SqlLiteCommand("select Date from [ShopRegistration]", conn) {
        conn.Open();
        dateTimePicker.MinDate = DateTime.ParseExact((string)cmd.ExecuteScalar(),
                                                     "yy-MMM-dd",
                                                     CultureInfo.InvariantCulture).Date;
    }
}

dateTimePicker.MaxDate = DateTime.Now.Date;
您需要使用System.Globalization添加
访问您的用户,以访问
文化信息

参考资料


当您尝试此代码时会发生什么情况?您是否故意忽略了连接到数据库的
SqlConnection
?如果没有,而且你还没有设置,那么你也需要完成。查询数据库后,分配值是一项过于简单的任务。您在这方面遇到了什么问题?你打开连接了吗?是的!SqliteConnection正常。给出运行时错误……。其他信息:“18-Jul-28 12:00:00 AM”的值对“MinDate”无效MinDate'必须小于MaxDate。正在显示相同的错误…其他信息:“18-Jul-28 12:00:00 AM”的值对“MinDate”无效MinDate'必须小于MaxDate。已调整,在了解您对格式的问题之前已获得原始答案。其他信息:字符串未被识别为有效的日期时间。请确保您的日期格式正确。您的查询返回什么?@“从[店铺注册]中选择日期”