0

I have a query which returns 66 rows, each of these rows contains a unique_id and I want to save the results in a List so I can use them for further queries. But the code freezes at the line which is supposed to add the rows to the list. I can't find where my problem is! This is My code:

public List<string> unique_id;
public List<string> get_unique_id_connection()
    {
        SQLiteConnection m_dbConnection;
        m_dbConnection = new SQLiteConnection("Data Source=akm.sqlite;version=3;");

        m_dbConnection.Open();
        string sql2 = "SELECT unique_id FROM mos_tbl WHERE region = 10";
        SQLiteCommand command2 = new SQLiteCommand(sql2, m_dbConnection);
        SQLiteDataReader rdr2 = null;
        rdr2 = command2.ExecuteReader();
        while (rdr2.Read())
        {
            for (int i = 0; i < rdr2.FieldCount; i++)
            {
                //MessageBox.Show(rdr2.GetValue(i).ToString());
                unique_id.Add(rdr2.GetValue(i).ToString());//This is where it freezes
            }
        }
        return unique_id;
    }

When I uncomment the MessageBox I can see the correct results, so I guess the problem is not the query.

4

1 回答 1

3

Are you sure there is no NullReferenceException thrown? It looks like there is no unique_id list object created while you're adding elements to it.

于 2013-07-05T13:17:17.983 回答