dimanche 17 avril 2016

Reading data from SQLite database to string array [duplicate]

This question already has an answer here:

I'm trying to to display information from a SQLite DB.

This is what I'm currently using but this will only display the last contact in the DB.

public ViewContacts()
{
    InitializeComponent();

    SQLiteConnection Connection;

    Connection = new SQLiteConnection("Data Source=C:\\MyDB.db;Version=3;");
    Connection.Open();

    string readdb = "select * from Contacts order by FullName";
    SQLiteCommand command = new SQLiteCommand(readdb, Connection);
    SQLiteDataReader reader = command.ExecuteReader();
    while (reader.Read())
        tbContacts.Text = (reader["FirstName"] + " " + reader["LastName"]);
}

How could I pass the results into a string array, so I could then use the array to add all of the contacts to tbContacts.Text?

Aucun commentaire:

Enregistrer un commentaire