SQLite:列“日期"不属于表 [英] SQLite: Column 'date' does not belong to table

查看:74
本文介绍了SQLite:列“日期"不属于表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SQLite数据库,其中包含以下列:_id,displayName,date

I have a SQLite Database with following columns: _id, displayName, date

使用以下csharp代码,我试图在Sqlite数据库中选择行,它适用于除日期以外的所有列!

Using following csharp code i am trying to Select rows in Sqlite Database, it works for all columns but the date!:

    try
    {
    SQLiteConnection mDBConnection = 
    new SQLiteConnection("Data Source=C:\\Users\\x86\\Desktop\\db forms\\instances.db");
        mDBConnection.Open();

        SQLiteCommand mycommand = new SQLiteCommand(mDBConnection);
        mycommand.CommandText = "SELECT _id, displayName, datetime(date) FROM instances";
        SQLiteDataReader reader = mycommand.ExecuteReader();
        dt.Load(reader);
        reader.Close();
        mDBConnection.Close();

        foreach(DataRow row in dt.Rows){
           string id = row["_id"].ToString();
           string displayName = row["displayName"].ToString();
           DateTime date = (DateTime)row["date"]; //Error Here: Column 'date' does not belong to table instances.
           string datefromDb = row["date"].ToString(); // Same Error with this line...
           MessageBox.Show(id + " " + displayName + " ");

        };            
        }



    catch (SQLiteException SqliteException)
    {
        MessageBox.Show(SqliteException.ToString());
    }

我收到此错误:列'date'不属于表实例.数据库中确实存在日期"列.如果我没有在datetime(...)中包装日期列,则会在dt.Load(reader)给出字符串未被识别为有效的DateTime";

I get this error: Column 'date' does not belong to table instances. The column 'date' actually does exists in the database. If i don't wrap date column in datetime(...) it gives "String was not recognized as a valid DateTime" at dt.Load(reader);

更新:这是数据库...其列和类型.

UPDATE: This is the database ... its columns and types.

数据库内部的日期数据.

Date Data Inside Database.

推荐答案

尝试使用此功能:

mycommand.CommandText = "SELECT _id, displayName, datetime(date, localtime) date FROM instances";

此行的状态

mycommand.CommandText = "SELECT _id, displayName, datetime(date) FROM instances";

localtime 会将您的 date 字符串转换为DateTime.

localtime will convert your date string into DateTime.

这篇关于SQLite:列“日期"不属于表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆