gpt4 book ai didi

c# - 查询抛出 "IndexOutOfRange"

转载 作者:太空宇宙 更新时间:2023-11-03 11:12:17 25 4
gpt4 key购买 nike

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com