以文本方式查看主题

-  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=52846)

--  作者:天若千颖
--  发布时间:2014/6/24 9:47:00
--  根据条件导出数据的问题
  如题,我想实现这样一个功能,一个含气量统计表中,一列是井名,另一列是小层名。当选择井名,小层名为空时,导出所有选定井的数据,当井名为空,小层名不为空时,导出所有选定小层名的井。当两个条件都选择时,导出同时符合两个条件的数据。当两个条件都不选时,导出所有的数据。

    如下,是程版帮助修改过的代码,还是存在问题:

Dim wellname As WinForm.ComboBox = e.Form.Controls("井名")
Dim layername As WinForm.ComboBox = e.Form.Controls("小层名")
Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" \'设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮
    Dim ex As New Exporter
    ex.Format = "excel"
    ex.SourceTableName = "含气量统计表" \'指定导出表
    Dim Filter As String
    If e.Form.Controls("井名").Text > ""
    Filter= "井名 = \'" & e.Form.Controls("井名").Text & "\'"
    End If
    If e.Form.Controls("小层名").Text > "" Then
    Filter= Filter & " 小层名 = \'" & e.Form.Controls("小层名").Text & "\'"
    End If
    Filter = Filter.TrimStart(" and ")
    ex.Filter = Filter
    ex.filepath = dlg.FileName  \'指定目标文件
    ex.Export() \'开始导出
End If

    以上代码可以实现,两个条件中使用单一条件数据导出,但是,当两个条件都选择时,错误提示:

     语法错误 (操作符丢失) 在查询表达式 \'井名 = \'Atria-1\' 小层名 = \'Atria Coal 2\'\' 中。

    当两个条件都为空时,提示:

    未将对象引用设置到对象的实例。


     请教各位专家,这个过滤到底该如何设置?

--  作者:有点甜
--  发布时间:2014/6/24 9:53:00
--  
Dim wellname As WinForm.ComboBox = e.Form.Controls("井名")
Dim layername As WinForm.ComboBox = e.Form.Controls("小层名")
Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" \'设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮
    Dim ex As New Exporter
    ex.Format = "excel"
    ex.SourceTableName = "含气量统计表" \'指定导出表
    Dim Filter As String = "1=1"
    If e.Form.Controls("井名").Text > ""
        Filter = filter & " and 井名 = \'" & welname & "\'"
    End If
    If e.Form.Controls("小层名").Text > "" Then
        Filter = Filter & " and 小层名 = \'" & layername & "\'"
    End If
    ex.Filter = Filter
    ex.filepath = dlg.FileName  \'指定目标文件
    ex.Export() \'开始导出
End If

--  作者:天若千颖
--  发布时间:2014/6/24 10:34:00
--  

非常感谢,不过,还是有问题。

 


图片点击可在新窗口打开查看此主题相关图片如下:tm截图未命名.jpg
图片点击可在新窗口打开查看


--  作者:有点甜
--  发布时间:2014/6/24 10:40:00
--  
Dim wellname As WinForm.ComboBox = e.Form.Controls("井名")
Dim layername As WinForm.ComboBox = e.Form.Controls("小层名")
Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" \'设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮
    Dim ex As New Exporter
    ex.Format = "excel"
    ex.SourceTableName = "含气量统计表" \'指定导出表
    Dim Filter As String = "1=1"
    If e.Form.Controls("井名").Text > ""
        Filter = filter & " and 井名 = \'" & welname.Text & "\'"
    End If
    If e.Form.Controls("小层名").Text > "" Then
        Filter = Filter & " and 小层名 = \'" & layername.Text & "\'"
    End If
    ex.Filter = Filter
    ex.filepath = dlg.FileName  \'指定目标文件
    ex.Export() \'开始导出
End If

--  作者:Bin
--  发布时间:2014/6/24 10:40:00
--  
Dim wellname As WinForm.ComboBox = e.Form.Controls("井名")
Dim layername As WinForm.ComboBox = e.Form.Controls("小层名")
Dim dlg As New SaveFileDialog \'定义一个新的SaveFileDialog
dlg.Filter= "Excel文件|*.xls" \'设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then \'如果用户单击了确定按钮
    Dim ex As New Exporter
    ex.Format = "excel"
    ex.SourceTableName = "含气量统计表" \'指定导出表
    Dim Filter As String = "1=1"
    If e.Form.Controls("井名").Text > ""
        Filter = filter & " and 井名 = \'" & welname.Text & "\'"
    End If
    If e.Form.Controls("小层名").Text > "" Then
        Filter = Filter & " and 小层名 = \'" & layername.text & "\'"
    End If
    ex.Filter = Filter
    ex.filepath = dlg.FileName  \'指定目标文件
    ex.Export() \'开始导出
End If
--  作者:天若千颖
--  发布时间:2014/6/24 12:46:00
--  

这次没有问题了,非常感谢!

Tks。