1

I have this code

public static void GetOnline1()
        {
            string query = "SELECT online FROM online";
            SQLiteCommand myCommand = new SQLiteCommand(query, myConnection);
            myConnection.Open();
            SQLiteDataReader result = myCommand.ExecuteReader();
            if (result.HasRows)
            {
                while (result.Read())
                {
                    Console.WriteLine(result["online"]);
                    //result["online"] to string array?
                }
            }
            myConnection.Close();

How i can convert result["online"] to a string array?

1

2 Answers 2

1

You need to create a new list of string before if(result.HasRows).

var list = new List<string>();

And then add result["online"] to list in while loop as following.

while(result.Read())
{
     list.Add(result["online"].ToString());
}
Sign up to request clarification or add additional context in comments.

Comments

0

Put the results in a List<string>:

var onlineList = new List<string>();
if (result.HasRows)
{
    while (result.Read())
    {
        Console.WriteLine(result["online"]);
        onlineList.Add(result["online"].ToString());
    }
}

If you need it as an array, you can use this: onlineList.ToArray()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.