日期:2014-05-18  浏览次数:20778 次

为何使用DataTable中的Select()方法会漏记录?
DataTable是我从数据库中查询取得的,然后使用Select()方法查询数据,发现偶尔会漏掉某些记录,打个比方,后台数据库有13条记录,下载到DataTable之后,应该也是有1条记录才对,可是使用相同条件,竟然没查到记录。
where ContainerNO like '%41' and Vessel = 286 and Voyage = 15606 And TallyType = 0
所有记录中,没有任何字段为null。

mWhere = "where ContainerNO like '%41' and Vessel = 286 and Voyage = 15606 And TallyType = 0";

System.Data.DataRow[] mMatches = Costaco.Common.GlobeValues.DSContainer.Tables["D1"].Select(mWhere);

这个查询之后,mMatches 的记录数为0,应该是为1才对,为何?



------解决方案--------------------
估计你的mWhere里用了不支持的运算符或关键字,才会“漏”。
------解决方案--------------------
探讨
DataTable是我从数据库中查询取得的,然后使用Select()方法查询数据,发现偶尔会漏掉某些记录,打个比方,后台数据库有13条记录,下载到DataTable之后,应该也是有1条记录才对,可是使用相同条件,竟然没查到记录。
where ContainerNO like '%41' and Vessel = 286 and Voyage = 15606 And TallyType = 0
……

------解决方案--------------------
mWhere = "where ContainerNO like '%41' and Vessel = 286 and Voyage = 15606 And TallyType = 0";

System.Data.DataRow[] mMatches = Costaco.Common.GlobeValues.DSContainer.Tables["D1"].Select(mWhere);

没有where 关键字,请去掉后试试

------解决方案--------------------
Select方法只需要具体的条件即可,不要再加一些where等关键词了
------解决方案--------------------

DataTable.Select(string) ?

select方法参数直接放筛选条件
------解决方案--------------------
探讨
DataTable是我从数据库中查询取得的,然后使用Select()方法查询数据,发现偶尔会漏掉某些记录,打个比方,后台数据库有13条记录,下载到DataTable之后,应该也是有1条记录才对,可是使用相同条件,竟然没查到记录。
where ContainerNO like '%41' and Vessel = 286 and Voyage = 15606 And TallyType = 0
……

------解决方案--------------------
探讨

不好意思,内容写错了

mWhere = " ContainerNO like '%41' and Vessel = 286 and Voyage = 15606 And TallyType = 0";

System.Data.DataRow[] mMatches = Costaco.Common.GlobeValues.DSContainer.Tables["D1"].Select(……

------解决方案--------------------
探讨

漏掉的那条记录当然也是满足查询条件的了。

------解决方案--------------------
把Where去掉,在Select中直接加入条件就可以了
------解决方案--------------------
查询语句有问题吧,