我可以从数据库中获取记录并将其放入对象中
for (int i = 0; i < selectedFishes.Length; i++)
{
string stm = "SELECT * FROM Data WHERE name='" + selectedFishes[i] + "'";
SQLiteCommand cmd = new SQLiteCommand(stm, conn);
SQLiteDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
fish[i] = new fish(rdr.GetString(0), rdr.GetDouble(1), rdr.GetDouble(2), rdr.GetDouble(3), rdr.GetDouble(4));
Console.WriteLine(fish[i].name + " " + fish[i].value1 + " " + fish[i].value2 + " " + fish[i].value3 + " " + fish[i].value4);//it can be displayed into console
}
}
MessageBox.Show(selectedFishes.Length.ToString()+" "+fish.Length.ToString());//results are same if the value >5 cant be displayed
for (int i = 0; i < fish.Length; i++)
{
Console.WriteLine(fish[i].name + " " + fish[i].value1 + " " + fish[i].value2 + " " + fish[i].value3 + " " + fish[i].value4);
}
为什么不能显示?错误是“对象引用未设置为对象的实例”谢谢之前