<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Using For Each to assign collection to collection data item in Product Forum</title>
    <link>https://community.blueprism.com/t5/Product-Forum/Using-For-Each-to-assign-collection-to-collection-data-item/m-p/67879#M20484</link>
    <description>&lt;P&gt;Working in Blue Prisms vb.net environment and currently building out an LDAP VBO utility. I have the below code, it will return the list of users in an AD Group i.e. &lt;CODE&gt;samAccountName&lt;/CODE&gt;, &lt;CODE&gt;givenname&lt;/CODE&gt; &amp;amp; &lt;CODE&gt;surname&lt;/CODE&gt;.&lt;/P&gt;
&lt;P&gt;My namespace imports used are:&lt;/P&gt;
&lt;PRE class="lang-vb prettyprint-override"&gt;&lt;CODE&gt;System
System.Drawing, System.Data
System.DirectoryServices
System.Collections.Generic
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My issue is with trying to loop through the resultset and store each row of data returned in my final collection data item, &lt;CODE&gt;colResults&lt;/CODE&gt;.&lt;/P&gt;
&lt;P&gt;I know I'm working with a collection and I'm aware that what I'm doing in my For Each loop is not correct, i.e. compile error:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;"String cannot be converted to System.Data.Datatable"&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But I'm unable to resolve.&lt;/P&gt;
&lt;P&gt;I've attempted to rewrite and use an index but syntactically I can't use &lt;CODE&gt;.Count&lt;/CODE&gt; with my &lt;CODE&gt;Properties.SearchResultCollection&lt;/CODE&gt;.&lt;/P&gt;
&lt;PRE class="lang-vb prettyprint-override"&gt;&lt;CODE&gt;Dim de As New DirectoryServices.DirectoryEntry("LDAP://" + Path)
Dim ds As New DirectoryServices.DirectorySearcher(de)
Dim srCol As DirectoryServices.SearchResultCollection
Dim sr As DirectoryServices.SearchResult

'Try and assume success
Success = True

Try

    ds.Filter = "(&amp;amp;(objectCategory=user)(memberOf=" + GroupDN + "))"
    ds.PropertiesToLoad.Add("givenname")
    ds.PropertiesToLoad.Add("sn")
    ds.PropertiesToLoad.Add("samAccountName")

    srCol = ds.FindAll()

    For Each sr In srCol
        If Not sr.GetDirectoryEntry.Properties("name").Value Is Nothing Then
            colResults = (sr.GetDirectoryEntry.Properties("givenname").Value.ToString())
            colResults = (sr.GetDirectoryEntry.Properties("sn").Value.ToString())
            colResults = (sr.GetDirectoryEntry.Properties("samAccountName").Value.ToString)
        End If
    Next
Catch e As System.Exception
    Success = False
End Try
&lt;/CODE&gt;&lt;/PRE&gt;

--------------------------------------------------&lt;BR /&gt;

&lt;B&gt;Disclaimer:&lt;/B&gt; This content was auto-posted from Stackoverflow. The original Stackoverflow question is here &lt;A href="https://stackoverflow.com/questions/62771276/using-for-each-to-assign-collection-to-collection-data-item"&gt;Stackoverflow Post&lt;/A&gt;, posted by &lt;A href="https://stackoverflow.com/users/9742098/gpionelson"&gt;GpioNelson&lt;/A&gt;.</description>
    <pubDate>Thu, 09 Jul 2020 12:04:00 GMT</pubDate>
    <dc:creator>Digital_WorkerB</dc:creator>
    <dc:date>2020-07-09T12:04:00Z</dc:date>
    <item>
      <title>Using For Each to assign collection to collection data item</title>
      <link>https://community.blueprism.com/t5/Product-Forum/Using-For-Each-to-assign-collection-to-collection-data-item/m-p/67879#M20484</link>
      <description>&lt;P&gt;Working in Blue Prisms vb.net environment and currently building out an LDAP VBO utility. I have the below code, it will return the list of users in an AD Group i.e. &lt;CODE&gt;samAccountName&lt;/CODE&gt;, &lt;CODE&gt;givenname&lt;/CODE&gt; &amp;amp; &lt;CODE&gt;surname&lt;/CODE&gt;.&lt;/P&gt;
&lt;P&gt;My namespace imports used are:&lt;/P&gt;
&lt;PRE class="lang-vb prettyprint-override"&gt;&lt;CODE&gt;System
System.Drawing, System.Data
System.DirectoryServices
System.Collections.Generic
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;My issue is with trying to loop through the resultset and store each row of data returned in my final collection data item, &lt;CODE&gt;colResults&lt;/CODE&gt;.&lt;/P&gt;
&lt;P&gt;I know I'm working with a collection and I'm aware that what I'm doing in my For Each loop is not correct, i.e. compile error:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;"String cannot be converted to System.Data.Datatable"&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But I'm unable to resolve.&lt;/P&gt;
&lt;P&gt;I've attempted to rewrite and use an index but syntactically I can't use &lt;CODE&gt;.Count&lt;/CODE&gt; with my &lt;CODE&gt;Properties.SearchResultCollection&lt;/CODE&gt;.&lt;/P&gt;
&lt;PRE class="lang-vb prettyprint-override"&gt;&lt;CODE&gt;Dim de As New DirectoryServices.DirectoryEntry("LDAP://" + Path)
Dim ds As New DirectoryServices.DirectorySearcher(de)
Dim srCol As DirectoryServices.SearchResultCollection
Dim sr As DirectoryServices.SearchResult

'Try and assume success
Success = True

Try

    ds.Filter = "(&amp;amp;(objectCategory=user)(memberOf=" + GroupDN + "))"
    ds.PropertiesToLoad.Add("givenname")
    ds.PropertiesToLoad.Add("sn")
    ds.PropertiesToLoad.Add("samAccountName")

    srCol = ds.FindAll()

    For Each sr In srCol
        If Not sr.GetDirectoryEntry.Properties("name").Value Is Nothing Then
            colResults = (sr.GetDirectoryEntry.Properties("givenname").Value.ToString())
            colResults = (sr.GetDirectoryEntry.Properties("sn").Value.ToString())
            colResults = (sr.GetDirectoryEntry.Properties("samAccountName").Value.ToString)
        End If
    Next
Catch e As System.Exception
    Success = False
End Try
&lt;/CODE&gt;&lt;/PRE&gt;

--------------------------------------------------&lt;BR /&gt;

&lt;B&gt;Disclaimer:&lt;/B&gt; This content was auto-posted from Stackoverflow. The original Stackoverflow question is here &lt;A href="https://stackoverflow.com/questions/62771276/using-for-each-to-assign-collection-to-collection-data-item"&gt;Stackoverflow Post&lt;/A&gt;, posted by &lt;A href="https://stackoverflow.com/users/9742098/gpionelson"&gt;GpioNelson&lt;/A&gt;.</description>
      <pubDate>Thu, 09 Jul 2020 12:04:00 GMT</pubDate>
      <guid>https://community.blueprism.com/t5/Product-Forum/Using-For-Each-to-assign-collection-to-collection-data-item/m-p/67879#M20484</guid>
      <dc:creator>Digital_WorkerB</dc:creator>
      <dc:date>2020-07-09T12:04:00Z</dc:date>
    </item>
  </channel>
</rss>

