Results 1 to 4 of 4

Thread: How to add more code in between inline xml

  1. #1

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    How to add more code in between inline xml

    hi Guys,

    I have this code:

    Code:
    Dim table As DataTable = New DataTable()
    table = BL.GetPeople(1)
    
     If (table.Rows.Count > 0) Then
    
                                Dim doc = <?xml version="1.0"?>
                                          <Registration xmlns="">
                                              <Header>
                                                
                                              </Header>
    
     <%= From people As DataRow In table.Rows _
                                                  Order By people("LearnerSurname") _
                                                  Select <Information>
                                                   <Biographical>
                                                                 <Record>
                                                     <LearnerSurname><%= people("LearnerSurname") %></LearnerSurname>
                                                                     <LearnerName1><%= people("LearnerName1") %></LearnerName1>
                                                                     <LearnerName2><%= people("LearnerName2") %></LearnerName2>
      </Record>
                                                             </Biographical>
    'insert code here
                                                         </Information> %>
    Now just before the closing of the </Information> node I need to insert a few more nodes based on the rows of another datatable but using a field called peopleid from the datarow above.

    I need to do something like:

    Code:
    dim dtSubjects as datatable = bl.GetSubjectsByPeopleID(people("peopleid")
    if dtSubjects.rows.count > 0 then
    
    <%= From subject As DataRow In dtSubjects.Rows _
                                                  Select <Subject xmlns="">
                                                     <Code><%= subject("code") %></Code>
                                                 </Subject>%>
    
    end if
    Please help me.

  2. #2
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,686

    Re: How to add more code in between inline xml

    Dependent on data and conditions use two From clauses in the LINQ statement i.e. where dt1 and dt2 are DataTable. Of course this can get sticky and complex with where conditions and checks for values and no values located in regards to the secondary table.

    Code:
    Dim Results = (From A In dt1 From B In dt2

  3. #3

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: How to add more code in between inline xml

    no worries. I figured out a way. Please can someone verify this is good practice.

    I wrote a function

    Code:
     Private Function GetSubjects(ByVal peopleID As Integer) As System.Collections.Generic.IEnumerable(Of XElement)
            Dim BL As New BLL
    
            Dim dtSubjects As DataTable = BL.GetSubjectCodesByPeopleID(peopleID)
    
            Dim elem = From subs As DataRow In dtSubjects.Rows _
                          Select <Subject>
                                     <Record>
                                         <Year><%= Now.Year %></Year>
                                         <Subject><%= subs("SubjectCode") %></Subject>
                                     </Record>
                                 </Subject>
    
            Return elem
        End Function
    and I call it after the Biographical node like so:

    Code:
                            </Record>
                                                             </Biographical>
                                                             <%= GetSubjects(people("peopleid")) %>
                                                         </Information> %>

  4. #4
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,686

    Re: How to add more code in between inline xml

    Not seeing where you introduce a second DataTable in that code

    This
    Code:
    subs("SubjectCode")
    is better done as
    Code:
    subs.Field(Of String)("SubjectCode")
    Or if not a string
    Code:
    subs.Field(Of Int32)("SubjectCode")

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width