我觉得这很奇怪,我有这样的代码:

string getBatchesQuery = "SELECT DISTINCT CONVERT(VARCHAR(8), time, 4) AS Batch FROM Calls ORDER BY Batch";
SqlCommand getBatchesQueryCom = new SqlCommand(getBatchesQuery, connection);

SqlDataReader getBatchesQueryReader = myCom.ExecuteReader();

List<string> allBatches = new List<string>();

while (getBatchesQueryReader.Read())
{

    allBatches.Add(getBatchesQueryReader["Batch"].ToString());

}
getBatchesQueryReader.Close();


现在怎么可能不存在Batch?也许是因为我这样命名吗?

我该怎么办?

最佳答案

该列不存在,因为您运行了错误的命令。将myCom更改为getBatchesQueryCom

SqlDataReader getBatchesQueryReader = getBatchesQueryCom.ExecuteReader();

关于c# - 查询抛出“IndexOutOfRange”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13552625/

10-11 03:32