Link to home
Start Free TrialLog in
Avatar of Ken H.
Ken H.

asked on

Code Loop to populate datatable which populates gridview

I have log files that need parsing.
One section has folders which are named after the systems they are generated from.
I need to code a loop that opens two log files in each folder and puts data i specify into a datatable that gets output to a gridview.

Below is a short version of my code. Right now it only returns the data from the logs in the first folder. I need it to loop through as many folders as exist in the directory. The number of folders can be between 0 and 6 depending on user settings for the data collection tool.
For Each slotConfigInfo As String In IO.Directory.GetFiles(txtPath.Text & "\StorageSystem\", "*_SlotConfigInfo.log", SearchOption.AllDirectories)
                For Each versionInfo As String In IO.Directory.GetFiles(txtPath.Text & "\StorageSystem\", "*_VersionInfo.log", SearchOption.AllDirectories)

                    Dim slotConfigData As String() = IO.File.ReadAllLines(slotConfigInfo)
                    Dim versionInfoData As String() = IO.File.ReadAllLines(versionInfo)
                    Dim systemName As String = slotConfigData(4).Substring(14)
                    Dim systemModel As String = slotConfigData(8).Substring(15)


                    'Create "FilerData" Data Table
                    Dim Table1 As DataTable
                    Table1 = New DataTable("FilerData")
                    'Declare 1 Row for data
                    Dim Row1 As DataRow

                    Try
                        'Declare column called Filer Name
                        Dim filerName As DataColumn = New DataColumn("Filer Name")
                        'Set Data Type for the column
                        filerName.DataType = System.Type.GetType("System.String")
                        'Add column to table
                        Table1.Columns.Add(filerName)

                        Dim Model As DataColumn = New DataColumn("Model")
                        filerModel.DataType = System.Type.GetType("System.String")
                        Table1.Columns.Add(filerModel)

                        'Declare new row
                        Row1 = Table1.NewRow()
                        'Fill row with data - Item property is used to set the field value
                        Row1.Item(filerName) = systemName
                        Row1.Item(filerModel) = systemModel
                        Table1.Rows.Add(Row1)

                    Catch ex As Exception

                    End Try

                    'Create new Dataset
                    Dim ds As New DataSet()
                    ds = New DataSet()
                    'Add the table to the dataset
                    ds.Tables.Add(Table1)
                    'Bind dataset to a gridview control
                    gridFilerProperties.DataSource = ds
                    gridFilerProperties.DataBind()


                Next
            Next

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of nepaluz
nepaluz
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Not sure what you are doing with the lines below
Dim systemName As String = slotConfigData(4).Substring(14)
Dim systemModel As String = slotConfigData(8).Substring(15)

Open in new window

however, your loop was creating a new Dataset each run and thus the last one was the only one you saw since the others were "detached" by setting a datasource in each loop. I have also removed the dataset and replaced it with a table.
Avatar of Ken H.
Ken H.

ASKER

EXCELLENT!!!

I need to make a few tweaks to that but I can work it from here.

The reason for those lines you were questioning is that I am cherry picking data out of the log file that is in static locations in the log. Those lines basically say grab line 4 starting at character 14, grab line 8 starting at character 15. there is some data i will have to write expressions to get.

This application development stuff has a steep learning curve for sure. Thank you for the excellent answer!