以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  关联查询,查询结果不对  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=34827)

--  作者:zhoushijun
--  发布时间:2013/6/17 10:44:00
--  关联查询,查询结果不对

        \'关联查询保证金
        Dim cmd As New SQLCommand
        cmd.C
        DataTables("GuarantyFundall").Load
        Tables("GuarantyFundall").Refresh
        Dim sql As String
        Dim yj As Integer=0
        If values.Length >1 Then
            sql="SELECT a.JTPH, a.buyer_name,sum(case when a.status = 1 and b.inout=1  then a.balance else  0 end)+sum(case when a.status = 1 and b.inout=0  then a.balance+a.amount else  0 end)+sum(case when a.status = 0 and b.inout=0  then a.amount else  0 end) as 可退保证金,sum(Case when a.status=1 Then a.balance Else 0 End) As balance FROM GuarantyFundall a LEFT JOIN GuarantyFund_Operation_Type b ON a.operation_type = b.operation_type  where (a.status = 1  Or (a.operation_type=2 And a.status=0)) and  a.buyer_name in(" & name & ") GROUP BY a.JTPH,a.buyer_name "
        Else
            sql="SELECT a.JTPH, a.buyer_name,sum(case when a.status = 1 and b.inout=1  then a.balance else  0 end)+sum(case when a.status = 1 and b.inout=0  then a.balance+a.amount else  0 end)+sum(case when a.status = 0 and b.inout=0  then a.amount else  0 end) as 可退保证金,sum(Case when a.status=1 Then a.balance Else 0 End) As balance FROM GuarantyFundall a LEFT JOIN GuarantyFund_Operation_Type b ON a.operation_type = b.operation_type  where (a.status = 1  Or (a.operation_type=2 And a.status=0)) and a.buyer_name=" & name & " GROUP BY a.JTPH,a.buyer_name"
        End If
       
       
        Dim dt As Table = Tables("GuarantyFundall")
        cmd.CommandText=sql
        dt.DataSource = cmd.ExecuteReader()
        tb12.Text=dt.Compute("sum(balance)")

 

sql语句没有问题,查出来的数据不是最新的!代码在命令窗口执行也不是最新的,sql语句在执行sql里面 数据就对了,和数据库一样!这是怎么回事


--  作者:blackzhu
--  发布时间:2013/6/17 10:47:00
--  
又是刷新 又是加载 又是SQL语句 真心看不懂
--  作者:zhoushijun
--  发布时间:2013/6/17 10:53:00
--  

之前只有加载的,看数据不是最新的,我又加了个刷新 试了一下 还是不行

 

 

问题是查询出来的结果跟数据库不一样,而且怎么查都是一个结果!

[此贴子已经被作者于2013-6-17 10:56:49编辑过]

--  作者:jspta
--  发布时间:2013/6/17 10:57:00
--  

你试试这句tables().fill(sql,数据源,true)

还有你直接在把语句做成视图,加载视图,不就简单多了吗


--  作者:zhoushijun
--  发布时间:2013/6/17 11:08:00
--  
我这个查询是没有对应表控件的,只想实现从外部数据库查询最新的数据