Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Optimizing speed result on this code
Message
From
05/02/2008 02:44:32
Al Doman (Online)
M3 Enterprises Inc.
North Vancouver, British Columbia, Canada
 
 
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:
01289440
Views:
11
>Is there a way to optimize the speed result on this code:
>
>
>        ' Adjust a dataset to avoid null values
>        ' expO1 Dataset
>        Public Function AdjustDataSetToAvoidNullValue(ByVal toDataSet As DataSet) As DataSet
>            Dim ldDate As Date = oApp.GetEmptyDate()
>            Dim loColumn As DataColumn
>            Dim loRow As DataRow
>            Dim loTable As DataTable
>
>            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
>
>                                Case "System.Integer"
>                                    loRow.Item(loColumn.ColumnName) = 0
>
>                                Case "System.Decimal"
>                                    loRow.Item(loColumn.ColumnName) = 0
>
>                                Case "System.Boolean"
>                                    loRow.Item(loColumn.ColumnName) = False
>
>                                Case Else
>                                    loRow.Item(loColumn.ColumnName) = ""
>
>                            End Select
>
>                        End If
>                    Next
>                Next
>            Next
>
>            Return toDataSet
>        End Function
>
>
>On a 7000 records dataset, which contains a lot of fields, this process can take up to 4 seconds.

A couple of ideas:

- Maybe you could prevent nulls in your DataSet in the first place, by using some sort of NVL()-equivalent function when you create it

- If you can apply SQL commands to a DataTable, then for each column in each DataTable you might be able to build an UPDATE statement. Fox pseudocode:
UPDATE SomeDataTable SET ;
  SomeColumn = SomeDefaultValue ;
  WHERE ISNULL( SomeColumn )
That way, you'd be executing ( "a lot of fields" ) SQL statements, instead of ( "a lot of fields" ) * ( lots of rows [e.g. 7000] ) If... Select Case code blocks.

- If there's any way to create temporary indices on a DataTable or DataSet it might be worth investigating
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform