场景:
SQLite数据库,在查询数据时,提示 标题错误异常。查看堆栈,是在SQLiteDataReader.CheckValidRow 时报错。
数据查询是通过 adapter.Fill(dt) 进行的;
分析:
看了网友的分析,有的说是改用SQLiteDataReader来先进行判断有无数据的。但这都不是我想要的解决方案。因为在Navicat for sqlite中是可以正常执行的。
改之前的语句如下:
SELECT b.OrgName,ifnull(a.bds,0)bds, ifnull(c.je,0) jhje,ifnull(a.bdje,0)bdje,ifnull(a.bdje*100/c.je,0) jd
from KJ_OrgInfo b LEFT JOIN (SELECT orgid, sum(bds) bds, sum(bdje) bdje
FROM
(
SELECT
(SELECT parentorgid FROM kj_orginfo WHERE orgid = j.dwid) orgid,bds,bdje
FROM rbmx j
WHERE j.tbjd = '2'
) h
GROUP BY orgid)a on a.orgid = b.OrgId,
jdjh c
where b.OrgLevel='2' and b.orgid = c.dwid and c.nd='2015' and c.jd='2' order by b.PXM
修改后语句:
SELECT b.OrgName,ifnull(a.bds,0)bds, ifnull(c.je,0) jhje,ifnull(a.bdje,0)bdje,ifnull(a.bdje*100/c.je,0) jd
from
jdjh c ,KJ_OrgInfo b LEFT JOIN (SELECT orgid, sum(bds) bds, sum(bdje) bdje
FROM
(
SELECT
(SELECT parentorgid FROM kj_orginfo WHERE orgid = j.dwid) orgid,bds,bdje
FROM rbmx j
WHERE j.tbjd = '2'
) h
GROUP BY orgid)a on a.orgid = b.OrgId
where b.OrgLevel='2' and b.orgid = c.dwid and c.nd='2015' and c.jd='2' order by b.PXM
解决:
隔了一夜再来看问题,怀疑是不是关联导致的,先把左关联去掉,正常执行,看来是关联导致的。再想,是不是先设置关联表的原因。又把c表提前,放到b的前面(from后面)。
成功!