我使用下面的内容填充目录的内容。
是否可以将数组列表的结果用作从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原因中添加一个多字符串参数的想法。还在努力弄清楚这是否有效
发布于 2014-03-17 14:57:59
破解了..。
必须与WHERE子句的字符串进行一些连接,但这是一个不错的选择。
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()发布于 2014-03-17 10:51:41
如果我将您的第一个代码块简化为
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)。欢迎来到现代世界。
如果您需要帮助重写大量遗留代码,请将其分解为对其他人有用的问题。
https://stackoverflow.com/questions/22445247
复制相似问题