' 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 FunctionI just found today that if I have an empty date, such as 1899-12-30T00:00:00-05:00, that the line which initializes loRow.Item() to something will replace the value with 2010-09-09T00:00:00-04:00.
' Equivalent of VFP StrTran() ' expC1 String ' expC2 Search for specific character ' expC3 Replace Public Function StrTran(ByVal tcSearchIn As String, ByVal tcSearchFor As String, _ ByVal tcReplace As String) As String Dim loStringBuilder As StringBuilder = New StringBuilder(tcSearchIn) Return loStringBuilder.Replace(tcSearchFor, tcReplace).ToString() End FunctionI really do not understand why calling StrTran() will change the value. This only happens when I have an empty value in the date. I just found out about it when sending some XML data from a Web Service method().