首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用Arraylist作为OLEDB查询的筛选器

使用Arraylist作为OLEDB查询的筛选器
EN

Stack Overflow用户
提问于 2014-03-17 00:54:30
回答 2查看 264关注 0票数 1

我使用下面的内容填充目录的内容。

是否可以将数组列表的结果用作从OLEDB查询中排除的项的筛选器?如果没有,有人能为我指出更好的选择吗?非常感谢。

代码语言:javascript
运行
复制
  Dim NodeFile As New IO.DirectoryInfo(tempMail & tvProgress.SelectedNode.FullPath)
            Dim NodeList As IO.FileInfo() = NodeFile.GetFiles("*.*")
            Dim report As New ArrayList()
            For Each NodeExcl In NodeList
                report.Add(Path.GetFileName(NodeExcl.Name))
            Next

查询码

代码语言:javascript
运行
复制
     Try

        Dim conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Me.aClients & ""
        Dim n As Integer


        For n = 0 To UBound(AllDetails)
            Dim NodeFile As New IO.DirectoryInfo(tempMail & tvProgress.SelectedNode.FullPath)
            Dim NodeList As IO.FileInfo() = NodeFile.GetFiles("*.*")
            Dim report As New ArrayList()
            For Each NodeExcl In NodeList
                report.Add(Path.GetFileName(NodeExcl.Name))
            Next

            '' Need to exclude arraylist from query

            If tvProgress.Nodes.Count = 0 Then Exit Sub

            If AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps = e.Node.Text Then
                lstRequired.DataSource = Nothing
                lstRequired.DataBindings.Clear()

                Dim eSearch As String = AllDetails(n).uCode
                Dim fSearch As String = AllDetails(n).uOps

                da.SelectCommand.Connection.ConnectionString = conn
                da.SelectCommand.CommandText = "SELECT Documents.DocName FROM Documents WHERE (Documents.UnitCode = ?) AND (Documents.OpName = ?) AND Documents.Required = True ORDER BY DocName"
                da.SelectCommand.Parameters.AddWithValue("@p1", eSearch)
                da.SelectCommand.Parameters.AddWithValue("@p2", fSearch)
                da.Fill(dt)
                dt.Rows.Add("Add Additional Requirement")
                lstRequired.DataSource = dt
                lstRequired.DisplayMember = StrConv("DocName", VbStrConv.ProperCase)
                lstRequired.Refresh()

                Dim dl As DataTable = CType(lstRequired.DataSource, DataTable)
                Using sR = New IO.StreamReader(tFiles & UCase("ProgExcluded.txt"))
                    While (sR.Peek() > -1)
                        Dim rows() = dl.Select("DocName = '" + sR.ReadLine + "'")
                        For Each row In rows
                            row.Delete()
                        Next
                        dl.AcceptChanges()
                    End While
                End Using

            End If
        Next

        Exit Sub


    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

我做了一些思考,现在修改了一些代码

代码语言:javascript
运行
复制
            Dim NodeFile As New IO.DirectoryInfo(tempMail & tvProgress.SelectedNode.FullPath)
            Dim NodeList As IO.FileInfo() = NodeFile.GetFiles("*.*")
            Dim report As New ArrayList()

            For Each NodeExcl In NodeList
                report.Add(Path.GetFileName(NodeExcl.Name))
            Next
            Dim newreport As String = String.Join(",", report.ToArray())

在where原因中添加一个多字符串参数的想法。还在努力弄清楚这是否有效

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-03-17 14:57:59

破解了..。

必须与WHERE子句的字符串进行一些连接,但这是一个不错的选择。

代码语言:javascript
运行
复制
Dim da As New OleDb.OleDbDataAdapter("", "")
        Dim dt As New DataTable
        Dim conn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Me.aClients & ""
        Dim n As Integer


        For n = 0 To UBound(AllDetails)
            If AllDetails(n).uName & " - " & AllDetails(n).uCode & " - " & AllDetails(n).uOps = e.Node.Text Then

                Dim NodeFile As New IO.DirectoryInfo(Path.Combine(tempMail, tvProgress.SelectedNode.FullPath))
                Dim reports = NodeFile.EnumerateFiles().Select(Function(f) Path.GetFileName(f.Name)).ToList()

                Dim newreport As String = String.Join("' AND Documents.DocName <> '", reports.ToArray())

                If tvProgress.Nodes.Count = 0 Then Exit Sub

                Dim eSearch As String = AllDetails(n).uCode
                Dim fSearch As String = AllDetails(n).uOps
                Dim gsearch As String = "'" & newreport & "'"

                da.SelectCommand.Connection.ConnectionString = conn
                da.SelectCommand.CommandText = "SELECT Documents.DocName FROM Documents WHERE (Documents.UnitCode = ?) AND (Documents.OpName = ?) AND (Documents.DocName <> " & gsearch & ") AND Documents.Required = True ORDER BY DocName"
                da.SelectCommand.Parameters.AddWithValue("@p1", eSearch)
                da.SelectCommand.Parameters.AddWithValue("@p2", fSearch)
                da.Fill(dt)

                dt.Rows.Add("Add Additional Requirement")
                lstRequired.DataSource = dt
                lstRequired.DisplayMember = "DocName"
                lstRequired.Refresh()
票数 0
EN

Stack Overflow用户

发布于 2014-03-17 10:51:41

如果我将您的第一个代码块简化为

代码语言:javascript
运行
复制
Dim NodeFile As New IO.DirectoryInfo( _
    Path.Combine(tempMail, tvProgress.SelectedNode.FullPath))
Dim reports = NodeFile.EnumerateFiles().Select(Function(f) _
    Path.GetFileName(f.Name)).ToList()

您将看到报告是一个List(Of String)。欢迎来到现代世界。

如果您需要帮助重写大量遗留代码,请将其分解为对其他人有用的问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22445247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档