Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Handling DB Nulls
Message
Information générale
Forum:
ASP.NET
Catégorie:
Conception classe
Divers
Thread ID:
01440804
Message ID:
01440813
Vues:
57
>The problem is that I'm getting casting errors when there are DB nulls., Is there a better way of dealing with this other than the IF statement I used above? I don't want a bunch of IF's around each line above.

This one comes from my framework. With the help of many members here, I have fine tuned it a little bit from time to time.
        ' Adjust a dataset to avoid null values
        ' expO1 Dataset
        Public Function AdjustDataSetToAvoidNullValue(ByVal toDataSet As DataSet) As DataSet
            Dim lcColumn As String = ""
            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
                        lcColumn = loColumn.ColumnName

                        If IsDBNull(loRow.Item(lcColumn)) Then

                            Select Case loColumn.DataType.ToString

                                Case "System.DateTime"
                                    loRow.Item(lcColumn) = ldDate

                                Case "System.Integer"
                                    loRow.Item(lcColumn) = 0

                                Case "System.Decimal"
                                    loRow.Item(lcColumn) = 0

                                Case "System.Boolean"
                                    loRow.Item(lcColumn) = False

                                Case "System.String"
                                    loRow.Item(lcColumn) = ""

                                Case "System.Int32"
                                    loRow.Item(lcColumn) = 0

                                Case Else
                                    DataErrorControlledByTheFramework("In " + _
                                     "DataXML.AdjustDataSetToAvoidNullValue(), the type " + _
                                     loColumn.DataType.ToString + " has not been defined.")

                            End Select

                        End If

                        ' The loXslCompiledTransform.Transform() cannot support NULL.
                        ' So, we have to remove them from the value.
                        loRow.Item(lcColumn) = oApp.StrTran(loRow.Item(lcColumn), Chr(0), "")

                    Next

                Next

            Next

            Return toDataSet
        End Function
You may adjust as needed. The goal is to replace null values with default empty values.
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform