Foxtable(狐表)用户栏目专家坐堂 → 动态组合表达式 语法错误:“null”运算符后缺少操作数 麻烦老师帮忙指导下 谢谢!


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

主题:动态组合表达式 语法错误:“null”运算符后缺少操作数 麻烦老师帮忙指导下 谢谢!

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


加好友 发短信
等级:七尾狐 帖子:1571 积分:11238 威望:0 精华:0 注册:2021/1/17 17:06:00
动态组合表达式 语法错误:“null”运算符后缺少操作数 麻烦老师帮忙指导下 谢谢!  发帖心情 Post By:2021/11/16 16:15:00 [只看该作者]

运行错误


当前代码如下:【红色部分为原来的正常使用代码】
Dim s As String
Dim l As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1")
For Each Index As Integer In l.CheckedIndices
    s = s & "," & l.Items(Index)
Next
s = s.trim(",")
Dim cs As String =  s

Dim idx As String = ""

Dim lst As new List(of String)
Dim flag As Boolean
Dim s1 As String = vars("不为空字段") & "is not null"
MessageBox.Show(s1)

Dim drs As List(Of  DataRow) = DataTables("表A").Select("第一列 is not null", cs)

Dim drs As List(Of  DataRow) = DataTables(Vars("btname")).Select(s1, cs)
MessageBox.Show("1")
Dim pdr As DataRow = drs(0)
Dim dr As DataRow
For i As Integer = 1 To drs.count - 1
    dr = drs(i)
    flag = False
    For Each c As String In cs.split(",")
        If pdr(c) <> dr(c) Then
            flag = True
            Exit For
        End If
    Next
    If flag = False Then
        If lst.Contains(pdr("_Identify")) = False
            lst.add( pdr("_Identify") )
        End If
        lst.add( dr("_Identify") )
    End If
    pdr = dr
Next

If lst.count > 0 Then
    idx = String.Join(",",lst.ToArray)
    Dim s2 As String = s1 & "And _Identify not In (" & idx.trim(",") & ")"
    MessageBox.Show(s2)

Tables("表A").filter = "第一列 is not null and _Identify not in (" & idx.trim(",") & ") "

    Tables(Vars("btname")).filter = s2
Else
    MessageBox.Show("没有重复数据!")
End If

 回到顶部
帅哥,在线噢!
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


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

Dim s1 As String = vars("不为空字段") & " is not null "

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


加好友 发短信
等级:七尾狐 帖子:1571 积分:11238 威望:0 精华:0 注册:2021/1/17 17:06:00
回复:(有点蓝)Dim s1 As String = vars("不为空字段...  发帖心情 Post By:2021/11/16 16:37:00 [只看该作者]

谢谢  按照老师的提醒  修改后现在又提示未找到列 [_Identify]。
图片点击可在新窗口打开查看
是采用如下代码导入的excel表数据
Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "Excel97文件|*.xls|Excel2007文件|*.xlsx" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
    Dim ip As New Importer
    ip.SourcePath = dlg.FileName '指定数据文件\
    Dim Str1 As String = FileSys.GetName(dlg.FileName)  '从文件路劲中获取文件名称
    Dim book As new XLS.Book(dlg.FileName)
Dim c6 As WinForm.ComboBox = e.Form.Controls("ComboBox6")
Dim a1 As Integer = c6.Value
    ip.SourceTableName = book.Sheets(a1).name '指定要导入的表
    ip.NewTableName =book.Sheets(a1).name  's '导入后的表名
    If Str1 > "" AndAlso Str1.Contains("xlsx") Then
        ip.Format="Excel2007"
    Else If Str1 > "" AndAlso Str1.Contains("xls") Then
        ip.Format="Excel"
    End If
    ip.Import()
    Dim tb As WinForm.Table = e.Form.Controls("Table1")
    tb.Table.DataSource = DataTables(book.Sheets(0).name)
End If

例子表中数据查询如下:
图片点击可在新窗口打开查看
当前比对代码如下:
Dim s As String
Dim l As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1")
For Each Index As Integer In l.CheckedIndices
    s = s & "," & l.Items(Index)
Next
s = s.trim(",")
Dim cs As String =  s
Dim idx As String = ""
Dim lst As new List(of String)
Dim flag As Boolean
Dim s1 As String = vars("不为空字段") & " is not null"
Dim drs As List(Of  DataRow) = DataTables(Vars("btname")).Select(s1, cs)
Dim pdr As DataRow = drs(0)
Dim dr As DataRow
For i As Integer = 1 To drs.count - 1
    dr = drs(i)
    flag = False
    For Each c As String In cs.split(",")
        If pdr(c) <> dr(c) Then
            flag = True
            Exit For
        End If
    Next
    If flag = False Then
        If lst.Contains(pdr("_Identify")) = False
            lst.add( pdr("_Identify") )
        End If
        lst.add( dr("_Identify") )
    End If
    pdr = dr
Next
If lst.count > 0 Then
    idx = String.Join(",",lst.ToArray)
    Dim s2 As String = s1 & " And _Identify not In (" & idx.trim(",") & ")"
    'Tables(Vars("btname")).filter = s2
    Dim dtb As New DataTableBuilder("比对表")
    Dim cnt As Integer = DataTables(Vars("btname")).DataCols.Count
    Dim nms(cnt-1) As String
    For i As Integer = 0 To cnt-1
        nms(i) = DataTables(Vars("btname")).DataCols(i).name
        dtb.AddDef(nms(i), Gettype(String), 255)
    Next
    dtb.Build()
    Dim tb3 As WinForm.Table = e.Form.Controls("Table3")
    tb3.Table.DataSource = DataTables("比对表")
    tb3.Table.AutoSizeCols() '自适应列宽
    tb3.Table.filter = s2
Else
    MessageBox.Show("没有重复数据!")
End If

 回到顶部
帅哥,在线噢!
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


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

execl表和临时表是不存在 [_Identify]列的

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


加好友 发短信
等级:七尾狐 帖子:1571 积分:11238 威望:0 精华:0 注册:2021/1/17 17:06:00
回复:(有点蓝)execl表和临时表是不存在 [_Ide...  发帖心情 Post By:2021/11/16 16:49:00 [只看该作者]

经过sql数据查询语句查询到的表中是含这个主键的呢  相关excel表格数据是直接通过导入命令导入到狐表项目里的  不是excel作为数据源使用

Dim s As String
Dim l As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1")
For Each Index As Integer In l.CheckedIndices
    s = s & "," & l.Items(Index)
Next
s = s.trim(",")
Dim cs As String =  s

Dim idx As String = ""

Dim lst As new List(of String)
Dim flag As Boolean
Dim s1 As String = vars("不为空字段") & " is not null"

Dim drs As List(Of  DataRow) = DataTables(Vars("btname")).Select(s1, cs)

Dim pdr As DataRow = drs(0)
Dim dr As DataRow
For i As Integer = 1 To drs.count - 1
    dr = drs(i)
    flag = False
    For Each c As String In cs.split(",")
        If pdr(c) <> dr(c) Then
            flag = True
            Exit For
        End If
    Next
    If flag = False Then
        If lst.Contains(pdr("_Identify")) = False
            lst.add( pdr("_Identify") )
        End If
        lst.add( dr("_Identify") )
    End If
    pdr = dr
Next

If lst.count > 0 Then
    idx = String.Join(",",lst.ToArray)
    Dim s2 As String = s1 & " And _Identify not In (" & idx.trim(",") & ")"
    Tables(Vars("btname")).filter = s2       怎么将这里筛选出来的数据  赋值到下面的比对表里面呢?
    
    
    Dim dtb As New DataTableBuilder("比对表")
    Dim cnt As Integer = DataTables(Vars("btname")).DataCols.Count
    Dim nms(cnt-1) As String
    For i As Integer = 0 To cnt-1
        nms(i) = DataTables(Vars("btname")).DataCols(i).name
        dtb.AddDef(nms(i), Gettype(String), 255)
    Next
    dtb.Build()
    
    Dim tb3 As WinForm.Table = e.Form.Controls("Table3")
    tb3.Table.DataSource = DataTables("比对表")
    tb3.Table.AutoSizeCols() '自适应列宽
    tb3.Table.filter = s2
    '以下代码怎么添加上述的S2这个筛选条件  让符合筛选条件的数据填充到比对表中
    For Each a1 As DataRow In DataTables(Vars("btname")).datarows
        If a1 IsNot Nothing Then
            Dim r As Row = Tables("比对表").addnew
            For Each dc As DataCol In DataTables(Vars("btname")).DataCols
                r(dc.name) = a1(dc.name)
            Next
        End If
    Next
    
Else
    MessageBox.Show("没有重复数据!")
End If

 回到顶部
帅哥,在线噢!
有点蓝
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


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

遍历Tables(Vars("btname")),不要遍历DataTables(Vars("btname"))

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


加好友 发短信
等级:七尾狐 帖子:1571 积分:11238 威望:0 精华:0 注册:2021/1/17 17:06:00
  发帖心情 Post By:2021/11/16 18:08:00 [只看该作者]


以下内容是专门发给有点蓝浏览



多行不同字段值比较  相同的时候  不弹出找不到主键的提示   不同的时候会提示找不到主键的提示  但是取消后依旧可以显示正常数据【老师有没有办法修正他】
图片点击可在新窗口打开查看
图片点击可在新窗口打开查看
图片点击可在新窗口打开查看


当行选择多个列值比对相同或不同  结果都如图一样   没有数据
图片点击可在新窗口打开查看


[此贴子已经被作者于2021/11/16 18:20:28编辑过]

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


加好友 发短信
等级:七尾狐 帖子:1571 积分:11238 威望:0 精华:0 注册:2021/1/17 17:06:00
回复:(有点蓝)遍历Tables(Vars("btname")),不要遍...  发帖心情 Post By:2021/11/16 18:19:00 [只看该作者]

修正了筛选表之后  数据还是没有得到完美显示,楼上已附上项目列子  麻烦老师指导下
因加密狗到期,目前暂时不能使用新版本的开发版   还望老师直接贴出修改处的代码内容  谢谢!


比对单行数据数据不相同的代码
Dim s As String
Dim l As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1")
For Each Index As Integer In l.CheckedIndices
    s = s & "," & l.Items(Index)
Next
s = s.trim(",")
Dim cs As String =  s

Dim filter As String = "1=2"
Dim ss() As String = s.split(",")
Dim s1 As String = ss(0)
For i As Integer = 1 To ss.length - 1
    filter = filter & " or " & s1 & " <> " & ss(i)
Next
msgbox(filter)
Tables(Vars("btname")).filter = filter
Dim dtb As New DataTableBuilder("比对表")
Dim cnt As Integer = DataTables(Vars("btname")).DataCols.Count
Dim nms(cnt-1) As String
For i As Integer = 0 To cnt-1
    nms(i) = DataTables(Vars("btname")).DataCols(i).name
    dtb.AddDef(nms(i), Gettype(String), 255)
Next
dtb.Build()
For Each a1 As Row In Tables(Vars("btname")).rows
    If a1 IsNot Nothing Then
        Dim r As Row = Tables("比对表").addnew
        For Each dc As Col In Tables(Vars("btname")).Cols
            r(dc.name) = a1(dc.name)
        Next
    End If
Next
Dim tb3 As WinForm.Table = e.Form.Controls("Table3")
tb3.Table.DataSource = DataTables("比对表")
tb3.Table.AutoSizeCols() '自适应列宽


比对单行数据相同的代码
Dim s As String
Dim l As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1")
For Each Index As Integer In l.CheckedIndices
    s = s & "," & l.Items(Index)
Next
s = s.trim(",")
Dim cs As String =  s

Dim filter As String = "1=2"
Dim ss() As String = s.split(",")
Dim s1 As String = ss(0)
For i As Integer = 1 To ss.length - 1
    filter = filter & " and " & s1 & " = " & ss(i)
Next
msgbox(filter)
Tables(Vars("btname")).filter = filter
Dim dtb As New DataTableBuilder("比对表")
Dim cnt As Integer = DataTables(Vars("btname")).DataCols.Count
Dim nms(cnt-1) As String
For i As Integer = 0 To cnt-1
    nms(i) = DataTables(Vars("btname")).DataCols(i).name
    dtb.AddDef(nms(i), Gettype(String), 255)
Next
dtb.Build()

For Each a1 As Row In Tables(Vars("btname")).rows
    If a1 IsNot Nothing Then
        Dim r As Row = Tables("比对表").addnew
        For Each dc As Col In Tables(Vars("btname")).Cols
            r(dc.name) = a1(dc.name)
        Next
    End If
Next

Dim tb3 As WinForm.Table = e.Form.Controls("Table3")
tb3.Table.DataSource = DataTables("比对表")
tb3.Table.AutoSizeCols() '自适应列宽

比对多行数据不相同的代码
Dim s As String
Dim l As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1")
For Each Index As Integer In l.CheckedIndices
    s = s & "," & l.Items(Index)
Next
s = s.trim(",")
Dim cs As String =  s

Dim idx As String = ""

Dim lst As new List(of String)
Dim flag As Boolean
Dim s1 As String = vars("不为空字段") & " is not null"

Dim drs As List(Of  DataRow) = DataTables(Vars("btname")).Select(s1, cs)

Dim pdr As DataRow = drs(0)
Dim dr As DataRow
For i As Integer = 1 To drs.count - 1
    dr = drs(i)
    flag = False
    For Each c As String In cs.split(",")
        If pdr(c) <> dr(c) Then
            flag = True
            Exit For
        End If
    Next
    If flag = False Then
        If lst.Contains(pdr("_Identify")) = False
            lst.add( pdr("_Identify") )
        End If
        lst.add( dr("_Identify") )
    End If
    pdr = dr
Next

If lst.count > 0 Then
    idx = String.Join(",",lst.ToArray)
    Dim s2 As String = s1 & " And _Identify not In (" & idx.trim(",") & ")"
    Tables(Vars("btname")).filter = s2
    msgbox(s2)
    
    Dim dtb As New DataTableBuilder("比对表")
    Dim cnt As Integer = DataTables(Vars("btname")).DataCols.Count
    Dim nms(cnt-1) As String
    For i As Integer = 0 To cnt-1
        nms(i) = DataTables(Vars("btname")).DataCols(i).name
        dtb.AddDef(nms(i), Gettype(String), 255)
    Next
    dtb.Build()
    
    Dim tb3 As WinForm.Table = e.Form.Controls("Table3")
    tb3.Table.DataSource = DataTables("比对表")
    tb3.Table.AutoSizeCols() '自适应列宽
    tb3.Table.filter = s2
    
    For Each a1 As Row In Tables(Vars("btname")).rows
        If a1 IsNot Nothing Then
            Dim r As Row = Tables("比对表").addnew
            For Each dc As Col In Tables(Vars("btname")).Cols
                r(dc.name) = a1(dc.name)
            Next
        End If
    Next
    
Else
    MessageBox.Show("没有重复数据!")
End If

比对多行数据相同的代码
Dim s As String
Dim l As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1")
For Each Index As Integer In l.CheckedIndices
    s = s & "," & l.Items(Index)
Next
s = s.trim(",")
Dim cs As String =  s

Dim idx As String = ""

Dim lst As new List(of String)
Dim flag As Boolean
Dim s1 As String = vars("不为空字段") & " is not null"
Dim drs As List(Of  DataRow) = DataTables(Vars("btname")).Select(s1, cs)
Dim pdr As DataRow = drs(0)
Dim dr As DataRow
For i As Integer = 1 To drs.count - 1
    dr = drs(i)
    flag = False
    For Each c As String In cs.split(",")
        If pdr(c) = dr(c) Then
            flag = True
            Exit For
        End If
    Next
    If flag = False Then
        If lst.Contains(pdr("_Identify")) = False
            lst.add( pdr("_Identify") )
        End If
        lst.add( dr("_Identify") )
    End If
    pdr = dr
Next

If lst.count > 0 Then
    idx = String.Join(",",lst.ToArray)
    'Tables(Vars("btname")).filter = vars("不为空字段") & "is not null and _Identify not in (" & idx.trim(",") & ") "

    Dim s2 As String = s1 & " And _Identify not In (" & idx.trim(",") & ")"
Tables(Vars("btname")).filter = s2
    Dim dtb As New DataTableBuilder("比对表")
    Dim cnt As Integer = DataTables(Vars("btname")).DataCols.Count
    Dim nms(cnt-1) As String
    For i As Integer = 0 To cnt-1
        nms(i) = DataTables(Vars("btname")).DataCols(i).name
        dtb.AddDef(nms(i), Gettype(String), 255)
    Next
    dtb.Build()
    
    Dim tb3 As WinForm.Table = e.Form.Controls("Table3")
    tb3.Table.DataSource = DataTables("比对表")
    tb3.Table.AutoSizeCols() '自适应列宽
    'tb3.Table.filter = s2
    
    For Each a1 As Row In Tables(Vars("btname")).rows
        If a1 IsNot Nothing Then
            Dim r As Row = Tables("比对表").addnew
            For Each dc As Col In Tables(Vars("btname")).Cols
                r(dc.name) = a1(dc.name)
            Next
        End If
    Next
Else
    MessageBox.Show("没有重复数据!")
End If
[此贴子已经被作者于2021/11/16 18:34:51编辑过]

 回到顶部
帅哥,在线噢!
有点蓝
  9楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


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

学会理解一下代码,只会抄是没有用的

比对单行数据相同的代码
Dim s As String
Dim l As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1")
For Each Index As Integer In l.CheckedIndices
    s = s & "," & l.Items(Index)
Next
s = s.trim(",")
Dim cs As String =  s

Dim filter As String = "1=1"

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


加好友 发短信
等级:七尾狐 帖子:1571 积分:11238 威望:0 精华:0 注册:2021/1/17 17:06:00
回复:(有点蓝)学会理解一下代码,只会抄是没有用的...  发帖心情 Post By:2021/11/16 21:56:00 [只看该作者]

谢谢老师那么晚还在辛苦指导   对于这个地方我确实有点困惑

找不同的数据   还得麻烦老师指导下!
Dim s As String
Dim l As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1")
For Each Index As Integer In l.CheckedIndices
    s = s & "," & l.Items(Index)
Next
s = s.trim(",")
Dim cs As String =  s

Dim filter As String = "1=2"
Dim ss() As String = s.split(",")
Dim s1 As String = ss(0)
For i As Integer = 1 To ss.length - 1
    filter = filter & " or " & s1 & " <> " & ss(i)     如果<>换成=号   上述1=2时  也会找到相同值的数据行
Next
msgbox(filter)
Tables(Vars("btname")).filter = filter

 回到顶部
总数 13 1 2 下一页