samedi 23 janvier 2016

In C# how to get while loop results outside loop as a String[] array

I'm new in C#, I'm using FiniSar.SQLite to connect with my database.db. i can easily get my while loop results inside loop.

but i want access all results outside loop as String[] array. i have shared my code with you, i really appreciate that if someone share good answer for me.

File >> Form1.cs

private void buttonStem_Click(object sender, EventArgs e)
{
    SQLiteConnection sqlite_conn;
    SQLiteCommand sqlite_cmd;
    SQLiteDataReader sqlite_datareader;

    sqlite_conn = new SQLiteConnection("Data Source=database.db;Version=3;New=False;Compress=True;");
    sqlite_conn.Open();
    sqlite_cmd = sqlite_conn.CreateCommand();

    sqlite_cmd.CommandText = "SELECT * FROM GList";
    sqlite_datareader = sqlite_cmd.ExecuteReader();

    string[] gList;

    while ( sqlite_datareader.Read() )
    {

         gList = sqlite_datareader.GetString(1);
    }

    gList = // { "cat", "dog", "horse" };  << " I want results OutSide Loop something like that "

    sqlite_conn.Close();
}

gList data loss outside loop

Aucun commentaire:

Enregistrer un commentaire