M
M
Michael2015-09-23 23:53:43
SQLite
Michael, 2015-09-23 23:53:43

Extracting data from sqlite c#?

There is a c# project with a connected database. The database contains 1 table with 4 columns: Name, Gender, Age, City. On the form I have a ListBox in which I extract the names of all people from the database. It is necessary for me that at a choice of any name in ListBox about this person the information (a floor, age, a city) was deduced.

void getData()
        {
            SQLiteConnection connection = new SQLiteConnection(string.Format("Data Source={0};", base));
            connection.Open();
            SQLiteCommand command = new SQLiteCommand("SELECT * FROM 'peoples';", connection);
            SQLiteDataReader people = command.ExecuteReader();

            while (people.Read())
            {
                object getname = people[0];
                listBox1.Items.Add(getname);
            }
            connection.Close();
        }

reader[0] outputs the entire column with names. I tried to display the entire contents of the line - it did not work.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Makarov, 2015-09-24
@Nipheris

"SELECT * FROM 'peoples';"

select name, year, age, city from peoples
Doing scheduled queries with an asterisk is bad manners, leave the asterisk for the administrative console.
string name = peopleReader.getString(peopleReader.getOrdinal("name"));

D
Dmitry Filandor, 2015-09-24
@LifeAct

look towards DbFacadeSQLite - a very handy library, I've been using it for a long time clip2net.com/s/3nU9eKo

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question