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:
我有一个返回66行的查询,每行包含一个unique_id,我想将结果保存在List中,以便我可以使用它们进行进一步的查询。但代码冻结在应该将行添加到列表的行。我找不到我的问题所在!这是我的代码:
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.
当我取消注释MessageBox时,我可以看到正确的结果,所以我猜问题不是查询。
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.
你确定没有抛出NullReferenceException吗?看起来在向元素添加元素时没有创建unique_id列表对象。
#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.
你确定没有抛出NullReferenceException吗?看起来在向元素添加元素时没有创建unique_id列表对象。