我正在使用以下内容填充目录内容的arraylist。
是否可以使用arraylist的结果作为要从OLEDB查询中排除的项目的过滤器?如果没有,有人可以指出我更好的选择方向 - 非常感谢
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
查询代码
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
我有点想法,现在改编了一些代码
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 cause中添加一个多字符串参数。仍在尝试解决这个问题
答案 0 :(得分:0)
如果我拿第一块代码并将其简化为
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)
。欢迎来到现代世界。
如果您需要帮助来重写遗留代码,请将其分解为对其他人有用的问题。