samedi 2 avril 2016

How to retrive date from sqlite database in c#

My code is bellow. I want to get date within a string variable.

//Code

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();

I want to take the date in a string variable. and then I will show date in a text box.

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire