'关联查询保证金
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里面 数据就对了,和数据库一样!这是怎么回事