Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Optimizing speed result on this code
Message
From
05/02/2008 05:18:47
 
 
To
05/02/2008 02:00:20
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01289437
Message ID:
01289450
Views:
10
Michael,

>Is there a way to optimize the speed result on this code:
>
>
>            For Each loTable In toDataSet.Tables
>                For Each loRow In loTable.Rows
>                    For Each loColumn In loTable.Columns
>                        If IsDBNull(loRow.Item(loColumn.ColumnName)) Then
>                            Select Case loColumn.DataType.ToString
>                                Case "System.DateTime"
>                                    loRow.Item(loColumn.ColumnName) = ldDate
>
>
>On a 7000 records dataset, which contains a lot of fields, this process can take up to 4 seconds.

I am assuming there is a sizeable amount of nulls in the data.

First of all you are accessing via names and objects instead of integers. At least for the loop on reach row I'd try accessing via index instead of loColumn.ColumnName. With ADO and ADO.net ver. 1.x this was markedly faster and I guess this will be true today as well.

Secondly, instead of comparing the loColumn.DataType.ToString's, why try to use the loColumn.DataType as selector ?

Thirdly, if there are many rows having null values you always run for each row with many null items the select
Select Case loColumn.DataType.ToString 
     Case "System.Fieldtype"
       loRow.Item(loColumn.ColumnName) = Fieldtype.Default
I have no idea how costly that case is - but I'd try to factor out identifying the default from the inner loop and use a caching approach.
For Each loTable In toDataSet.Tables
    loRow = loTable.Row[0]
    lnStop = loRow.Columns.Count-1
    For lnFld  = 0 to lnStop
        /// save the default for that field no. to the best caching structure
        /// in vfp it would just be an array, as each field can have its own data type
    next
    For Each loRow In loTable.Rows
        For lnFld  = 0 to lnStop
           /// Check and replace if necessary
        next
    next
next
Fourthly, isn't there an isNull() method on the rows and/or column object ?

Fifthly, You can set your datatable columns to allow nulls or not - perhaps using this you can eliminate a lot of checks or set defaults correctly from start on.

I am probably off on .net syntax, as I did only a bit of java an C recently in static languages, so think more on the concepts than taking my syntax for gospel.

HTH

thomas
Previous
Reply
Map
View

Click here to load this message in the networking platform