Dataset Error : There is no row at position 0

Dataset Error : There is no row at position 0

我对这个错误感到很困惑,不知道从哪里继续寻找。下面的代码获取了一个客户列表,如果客户没有在数据库搜索中列出的条目,则迭代该列表调用 main() (COUNT 上的值 = 0)。

这在上周工作得很好,但今天只有最小的变化(评论 SQL 查询),当我在中断中审查的所有列出的数据集时,在 select 客户(不是全部)上抛出 IndexError点具有索引 [0].

的行

此时我什至没有调用任何行,它在 main(self, customer) 上抛出异常并且 customer 是一个字符串。

    def __init__(self):
        self.ui = wpf.LoadComponent(self, 'storageInvoicing.xaml')

        self.databaseHead = 'db'
        self.databaseDet = 'db'

        customerList = invoiceQuery("SELECT DISTINCT(custno) from db order by custno")

        #self.invoiceNumber = invoiceQuery("SELECT TOP 1 invoicenumber FROM db order by invoicenumber desc")
        self.invoiceNumber = invoiceQuery("SELECT TOP 1 invno FROM db ORDER BY invno DESC")

        self.invoiceNumber = str(self.invoiceNumber.Tables[0].Rows[0][0])

        self.start_time = time.time()

        self.startDate = '10-28-2019'
        self.endDate = '11-03-2019'
        self.gstRate = 0.10

        for i in range(0, len(customerList.Tables[0].DefaultView)):
            customer = customerList.Tables[0].Rows[i][0]
            customer = customer.replace("'", r"''")
            invoiceCheck = invoiceQuery("SELECT COUNT(*) from db where custno = '%s' and invoicedate = '%s'" % (customer, self.endDate))

            if invoiceCheck.Tables[0].Rows.Count > 0:
                if invoiceCheck.Tables[0].Rows[0][0] == 0:
                    try:
                        self.main(customer.strip()) ## THROWS EXCEPTION HERE ##
                    except Exception as e:
                        print(e)

        print("--- %s seconds ---" % (time.time() - self.start_time))

以下内容直接来自当地人,在客户抛出错误时:

customerList在locals中看到总共有3334行数据> [3334] 数据行

invoiceCheck 在locals中看到一共1行> [0] 数据行

内存中所有当前数据集的索引都为 0 或更大,但我仍然在 self.main(customer.strip())

上收到错误

编辑:

更改日期范围会影响引发错误的客户列表。

我设法解决了这个问题,结果发现这是 SQL 中的数据问题,删除并重新导入 table 解决了这个问题。