K
K
Kirill2020-08-03 18:08:52
MySQL
Kirill, 2020-08-03 18:08:52

How to add specific row to MySqlDataReader?

There is a table with one column.
I need to move it to an array.

How I am trying to do this:

string[] botusers = new string[0];
MySqlDataReader reader = findCommand.ExecuteReader();
     while (reader.Read())
     {
         for (var i = 0; i < reader.FieldCount; i++)
         {
             Array.Resize(ref botusers, botusers.Length + 1);
             botusers[i] = /*Как добавить строку под номером i*/;
         }
     }


The essence of the question: how to add a certain row i from the table to the botusers[i] array using a loop?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grish Poghosyan, 2020-08-03
@BPL

Why is it so difficult ... If I understand you correctly, then this is what you need.

var botusers = new List<string>();
using(var reader = findCommand.ExecuteReader())
{
    while(reader.Read())
    {
        botusers.Add(reader.GetString(1));
    }
}

But it is better to familiarize yourself with asynchronous programming on the web.
var botusers = new List<string>();
using(var reader = await findCommand.ExecuteReaderAsync())
{
    while(await reader.ReadAsync())
    {
        botusers.Add(reader.GetString(1));
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question