Foxtable(狐表)用户栏目专家坐堂 → [求助]


  共有256人关注过本帖树形打印复制链接

主题:[求助]

帅哥哟,离线,有人找我吗?
Liuxinyu
  1楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:164 积分:1488 威望:0 精华:0 注册:2012/1/4 13:13:00
[求助]  发帖心情 Post By:2020/10/31 19:01:00 [只看该作者]

老师好!请求帮助:选择下图中未选择的参数,不论是单选或是集合,都可以运行。选择下图中已选的参数,运行出错,是什么原因?

图片点击可在新窗口打开查看

代码如下:
图片点击可在新窗口打开查看

' 提取 持股人名单
Dim sq As String = "Select [_identify], shAccountSZ, shName Fro m {ShareHolder} where [shCompanyPost] in (" & sv & ")"
Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = sq
Dim dt As DataTable
dt = cmd.ExecuteReader(True)

[此贴子已经被作者于2020/11/8 10:20:24编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:60740 积分:307877 威望:0 精华:8 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/11/1 20:09:00 [只看该作者]

这个错误和sql没有关系,请贴出出错函数的完整代码,不要截图:http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&Id=69632

 回到顶部
帅哥哟,离线,有人找我吗?
Liuxinyu
  3楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:164 积分:1488 威望:0 精华:0 注册:2012/1/4 13:13:00
  发帖心情 Post By:2020/11/8 10:24:00 [只看该作者]

 '##############################################
'    持有股份 统计
'**********************************************
'  参数: Args(0) 查询条件

Dim tb As Table = Tables("持股统计_Table2")
Dim tvw As WinForm.TreeView = Forms("持股统计").Controls("TreeView1")
Dim nd As WinForm.TreeNode
Dim sv As String
' 提取 查询条件
For Each nd In tvw.AllNodes
    If nd.Checked Then
        sv = sv & ", '" & nd.Name & "'"
    End If
Next
Dim sn() As String
If sv = "" Then
    Return Nothing
Else
    sv = sv.Trim(","," ")
End If

tb.StopRedraw
' 提取 持股人名单
Dim sq As String = "Select [_identify], shAccountSZ, shName Fro m {ShareHolder} where [shCompanyPost] in (" & sv & ")"
Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = sq
Dim dt As DataTable
dt = cmd.ExecuteReader(True)

Dim nrec As Integer = dt.DataRows.Count
If nrec = 0 Then Return Nothing
Dim nr As Integer = tb.Rows.Count
Select Case nr - nrec
    Case <0
        nr = nrec - nr
        tb.AddNew(nr)
    Case >0
        Do
            nr = nr - 1
            tb.Rows(nr).Delete
        Loop While nr > nrec
End Select

nr = 0
For Each dr As DataRow In dt.DataRows
    tb.Rows(nr)("股份持有人") = dr("shName")
    tb.Rows(nr)("账户") = dr("shAccountSZ")
    nr = nr + 1
    If nr = nrec Then Exit For
Next

Dim odb As WinForm.DateTimePicker = Forms("持股统计").Controls("dtpBegin")
Dim ode As WinForm.DateTimePicker = Forms("持股统计").Controls("dtpStop")
Dim ndb As Date
Dim nde As Date
Dim nsum As Long
Dim nbl As Double

' 提取 持股统计日期
sq = "Select top 1 hqHoldDate Fro m {ShareQuantity} where [hqHoldDate] <= #" & odb.Value & "# Order by hqHoldDate DESC"
cmd = New SQLCommand
cmd.C
cmd.CommandText = sq
ndb = cmd.ExecuteScalar()
sq = "Select top 1 hqHoldDate Fro m {ShareQuantity} where [hqHoldDate] <= #" & ode.Value & "# Order by hqHoldDate DESC"
cmd.CommandText = sq
nde = cmd.ExecuteScalar()

For Each tr As Row In tb.Rows
    ' 提取 期初持股数
    sq = "Select hqHoldQuantity Fro m {ShareQuantity} where [hqHoldDate] = #" & ndb & "# And [hqAccountSZ] = '" & tr("账户") & "'"
    cmd.CommandText = sq
    Dim nv As Long = cmd.ExecuteScalar   <-----当数据表中不存在某个账户信息时,返回出错,而不是 Nothing
    tr("期初持股数量") = nv
    ' 提取 期末持股数
    sq = "Select hqHoldQuantity, hqHoldingRadio Fro m {ShareQuantity} where [hqHoldDate] = #" & nde & "# And [hqAccountSZ] = '" & tr("账户") & "'"
    cmd.CommandText = sq
    Dim val = cmd.ExecuteValues
    tr("期末持股数量") = val("hqHoldQuantity")
    tr("期末持股比例%") = val("hqHoldingRadio")
Next

' 提取 期末限售统计日期
sq = "Select top 1 pqHoldDate Fro m {ShareRestrict} where [pqHoldDate] <= #" & ode.Value & "# Order by pqHoldDate DESC"
cmd.CommandText = sq
nde = cmd.ExecuteScalar()

' 统计 查询期末限售数
For Each tr As Row In tb.Rows
    sq = "Select pqRestrictedQuantity as qty Fro m {ShareRestrict} where [pqHoldDate] = #" & nde & "# AND [pqAccountSZ] = '" & tr("账户") & "'"
    cmd.CommandText = sq
    Dim nv As Long = cmd.ExecuteScalar
    tr("期末持有_限售股份数量") = nv
Next

tb.ResumeRedraw
tb.DataTable.AcceptChanges
Return "OK"
[此贴子已经被作者于2020/11/27 13:34:41编辑过]

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:60740 积分:307877 威望:0 精华:8 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/11/8 20:21:00 [只看该作者]

调试一下,看是哪一句代码出错?http://www.foxtable.com/webhelp/topics/1485.htm

这段代码有点迷惑,不知道是干嘛用的
Dim nrec As Integer = dt.DataRows.Count
If nrec = 0 Then Return Nothing
Dim nr As Integer = tb.Rows.Count
Select Case nr - nrec
    Case <0
        nr = nrec - nr
        tb.AddNew(nr)
    Case >0
        Do
            nr = nr - 1
            tb.Rows(nr).Delete
        Loop While nr > nrec
End Select

 回到顶部
帅哥哟,离线,有人找我吗?
Liuxinyu
  5楼 | QQ | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:幼狐 帖子:164 积分:1488 威望:0 精华:0 注册:2012/1/4 13:13:00
  发帖心情 Post By:2020/11/26 15:23:00 [只看该作者]

请教如何解决?错误出现在这段语句中:
For Each tr As Row In tb.Rows
    ' 提取 期初持股数
    sq = "Select hqHoldQuantity Fro m {ShareQuantity} where [hqHoldDate] = #" & ndb & "# And [hqAccountSZ] = '" & tr("账户") & "'"
    cmd.CommandText = sq
    Dim nv As Long = cmd.ExecuteScalar
    tr("期初持股数量") = nv
    ' 提取 期末持股数
    sq = "Select hqHoldQuantity, hqHoldingRadio Fro m {ShareQuantity} where [hqHoldDate] = #" & nde & "# And [hqAccountSZ] = '" & tr("账户") & "'"
    cmd.CommandText = sq
    Dim val = cmd.ExecuteValues    <----如果数据中不存在某账户,则出现错误

    tr("期末持股数量") = val("hqHoldQuantity")
    tr("期末持股比例%") = val("hqHoldingRadio")
Next



 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:60740 积分:307877 威望:0 精华:8 注册:2015/6/24 9:21:00
  发帖心情 Post By:2020/11/26 15:26:00 [只看该作者]

if val("hqHoldQuantity").ToString<> Nothing then
tr("期末持股数量") = val("hqHoldQuantity")
end if 
if val("hqHoldingRadio").ToString<> Nothing then
……

 回到顶部