我在 C# 中有以下代码:
string query = "SELECT * FROM Zboruri WHERE cod_aeroport = " + country;
using (var command = new SqlCommand(query, connection))
{
var list = new ArrayList();
var reader = command.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
string data1 = reader.GetString(1);
string data2 = reader.GetString(2);
list.Add(cod_aeroport);
list.Add(data1);
list.Add(data2);
}
}
else
{
string raspuns = "nu este info";
list.Add(raspuns);
}
reader.Close();
connection.Close();
return list;
}
我的数据库表有这些列:
data1(numeric(18,0))
data2(numeric(18,0))
...........
它给了我错误:
指数数组的边界之外。
在这行代码上:
string data2 = reader.GetString(2);
如何修复错误?