I have a working SQLite database from which I can successfully iterate through and DebugLog each entry in the database no problem.
My issue is that when trying to iterate through the database and add each entry to an array as an array, I am met with the following error:
NullReferenceException: Object reference not set to an instance of an object
DBManager.DisplayQuotes () (at Assets/Scripts/DBManager.cs:35)
DBManager.Start () (at Assets/Scripts/DBManager.cs:16)
Here is the code I am working with:
private string dbName = "URI=file:Quotes.db";
public object[][] quotesList;
void Start()
{
# Line 16 is below.
DisplayQuotes();
}
private void DisplayQuotes()
{
using (var connection = new SqliteConnection(dbName))
{
connection.Open();
// set up an object called command for db control
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT * FROM quotes;";
using (IDataReader reader = command.ExecuteReader())
{
int idx = 0;
while (reader.Read())
{
Debug.Log("Quote: " + reader["text"] + "\tAuthor: " + reader["author"]);
# Line 35 is below.
quotesList[idx] = new object[] { reader["code"], reader["text"], reader["author"], reader["category"], reader["length"], reader["difficulty"] };
idx++;
}
reader.Close();
}
}
connection.Close();
}
}