Blog Post
AndreaF
5 months agoContributor III
Thank you, the link has been very helpful!
I am leaving here an snippet of how I've changed my piece of code from above, in case somebody else want to have fun 😉
Dim ApplicationDt As DataTable
'Get a connection to the application db
Using dbConnApp As DBConnInfo = BRAPi.Database.CreateApplicationDbConnInfo(si)
'Perform the query
ApplicationDt = BRApi.Database.ExecuteSql(dbConnApp, SqlString.ToString, True)
End Using
Dim FrameworkDt As DataTable
'Get a connection to the framework db
Using dbConnFW As DbConnInfo = BRApi.Database.CreateFrameworkDbConnInfo(si)
'Perform the query
FrameworkDt = BRApi.Database.ExecuteSql(dbConnFW, "SELECT Name,Email FROM SecUser", True)
End Using
'Create the dataset
Dim dsn As New DataSet("DetailedDataAttachment")
'Add tables
dsn.Tables.add(ApplicationDt)
dsn.Tables.add(FrameworkDt)
'Create the relations
dsn.Relations.Add("CreatedNameRelation", dsn.Tables(0).Columns("CreatedUserName"), dsn.Tables(1).Columns("Name"), False)
dsn.Relations.Add("LastEditedNameRelation", dsn.Tables(0).Columns("LastEditedUserName"), dsn.Tables(1).Columns("Name"), False)
'Initialise string variables
Dim rowString As String = String.Empty
Dim finalString As String = String.Empty
Using writer As New StreamWriter(filePath)
writer.WriteLine(headerString)
For Each dataAttachmentRow As DataRow In ApplicationDt.Rows
rowString = String.Join(",", dataAttachmentRow.ItemArray)
For Each detailRow1 As DataRow In dataAttachmentRow.GetChildRows("CreatedNameRelation")
finalString = rowString & "," & detailRow1("Email")
Next
For Each detailRow2 As DataRow In dataAttachmentRow.GetChildRows("LastEditedNameRelation")
finalString = finalString & "," & detailRow2("Email")
Next
writer.WriteLine(finalString)
Next
End Using