如何从sqlite数据库中检索日期

时间:2016-04-02 10:52:26

标签: c# database sqlite date

我的代码如下。我想在字符串变量中获取日期。

SQLiteCommand sqlite_cmd;
SQLiteDataReader sqlite_datareader;
SQLiteConnection sqlite_conn;

// create a new database connection:
sqlite_conn = new SQLiteConnection(sConnectionString);

// open the connection:
sqlite_conn.Open();

// create a new SQL command:
sqlite_cmd = sqlite_conn.CreateCommand();

//Check is there any project with the same information
sqlite_cmd.CommandText = "Select * from prework;";

try
{
    sqlite_datareader = sqlite_cmd.ExecuteReader();
    while (sqlite_datareader.Read()) // Read() returns true if there is still a result line to read
    {
        // Print out the content of the text field:
        //String str = sqlite_datareader["date"].ToString();
        String str = Convert.ToDateTime(sqlite_datareader[4].ToString());
        MessageBox.Show(""+str);
    }
}
catch
{
    MessageBox.Show("error");
}

sqlite_conn.Close();

我想在字符串变量中取日期。然后我将在文本框中显示日期。

0 个答案:

没有答案