P
P
Pixilys2020-02-28 12:07:58
SQLite
Pixilys, 2020-02-28 12:07:58

So how do you get data from SQLite?

Help out, explain on your fingers how to get the data from the table.
The docks don't help, or I'm stoned on them, and I don't see the obvious.
Adding and updating records works.

public conn(string namebase)
        {
            string baseName = namebase + ".db";
            string pathString = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "db", baseName);
            string connectionString = string.Format("Data Source={0};", pathString);
            //string CommandText = "SELECT 'name', 'datebirth' FROM 'settungs' WHERE id='2'";
            string CommandText = "SELECT 'name', 'datebirth' FROM 'settungs'";

            SQLiteConnection connection = new SQLiteConnection(connectionString);
            connection.Open();

            SQLiteCommand command = new SQLiteCommand(CommandText, connection);
            SQLiteDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                //object name = reader["name"];//System.IndexOutOfRangeException: "Индекс находился вне границ массива."

                //var name = reader[0].ToString();
                //var name = reader[1].ToString();
                //MessageBox.Show(name);// Даёт [0] = name или [1] = datebirth

                //var name = reader.GetName(0).ToString();
                //MessageBox.Show(name);//Даёт 'name'

                //var name = reader.GetValue(0).ToString();
                //var name = reader.GetValue(1).ToString();
                //MessageBox.Show(name);//Также даёт название столбцов
            }

            connection.Close();
        }

Again, without result, it gives only the names of the columns.
for (int i = 0; i < reader.FieldCount; i++)
            {
                
                while (reader.Read())
                {
                    MessageBox.Show(string.Format("{0}\t{1};", reader.GetValue(0).ToString(), reader.GetValue(1).ToString()));
                }
            }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pixilys, 2020-02-28
@Pixilys

Thanks to curator freeExec. The matter turned out to be in quotation marks, in the request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question