C# sqlite 无法辨认的datetime格式 FromOADate

再念博不可控数据库datetime字段时,遇到了一个奇葩问题——“无法识别的datetime格式”

搞了半天……

数据库里看:2017-06-06 10:28:30.000

莫举行拍卖查询报错:“无法分辨的datetime格式”

举行拍卖后查出来sqlite个:42892.4364583333

……

属下这么处理

DateTime dtr = DateTime.FromOADate(42863.5656134259);
                double ewr = dtr.ToOADate();
                DateTime val = new DateTime(1899, 12, 31);
                val = val.AddDays(42863.5656134259);

SQLiteConnection connection= new SQLiteConnection(string.Format(
                            "Data Source={0}skpdb_539900210037.db3;Version=3;",
                            AppDomain.CurrentDomain.SetupInformation.ApplicationBase));//              
                connection.Open();
                DataTable dt = new DataTable();
                //connection.Open();
                SQLiteCommand command = new SQLiteCommand(connection);
                command.CommandText = "select CAST(kprq AS double) from zzs_fpkj order by kprq";
                SQLiteDataAdapter adapter = new SQLiteDataAdapter(command);
                adapter.Fill(dt); 
                foreach (DataRow dr in dt.Rows)
                {
                    string aaa = DateTime.FromOADate(Convert.ToDouble(dr[0])).ToString();
                    Console.WriteLine(aaa);
                }
                connection.Close();

  

网站地图xml地图