dbutility.vb

来自「使用Access数据库演示的任务分配管理程序 一个使用ADO.NET基于」· VB 代码 · 共 109 行

VB
109
字号
'------------------------------------------------------------------------------
' <auto-generated>
'     This code was generated by a tool.
'     Runtime Version:2.0.50727.42
'
'     Changes to this file may cause incorrect behavior and will be lost if
'     the code is regenerated.
' </auto-generated>
'------------------------------------------------------------------------------

Option Strict Off
Option Explicit On

Imports Microsoft.VisualBasic
Imports Microsoft.VisualBasic.Information
Imports System

'*************************************************************
' Class Name:  dbUtility
' Purpose:  Class used to convert Null values
' Description: 
'***************************************************************
Namespace Database
    
    Public Class dbUtility
        
        Shared Function NullToZero(ByVal o As Object) As Double
            Dim IsInvalid As Boolean = false
            If (o Is Nothing) Then
                IsInvalid = true
            End If
            If (Convert.IsDBNull(o) = true) Then
                IsInvalid = true
            End If
            If (Information.IsNumeric(o) <> true) Then
                IsInvalid = true
            End If
            If (IsInvalid = true) Then
                Return 0
            Else
                Return Convert.ToDouble(o)
            End If
        End Function
        
        Shared Function NullToString(ByVal o As Object) As String
            Dim IsInvalid As Boolean = false
            If (o Is Nothing) Then
                IsInvalid = true
            End If
            If (Convert.IsDBNull(o) = true) Then
                IsInvalid = true
            End If
            If (IsInvalid = true) Then
                Return ""
            Else
                Return Convert.ToString(o)
            End If
        End Function
        
        Shared Function NullToDate(ByVal o As Object) As Date
            Dim IsInvalid As Boolean = false
            If (o Is Nothing) Then
                IsInvalid = true
            End If
            If (Convert.IsDBNull(o) = true) Then
                IsInvalid = true
            End If
            If (Information.IsDate(o) <> true) Then
                IsInvalid = true
            End If
            If (IsInvalid = true) Then
                Return New Date(1918, 1, 1)
            Else
                Return Convert.ToDateTime(o)
            End If
        End Function
        
        Shared Function NullToBool(ByVal o As Object) As Boolean
            Dim IsInvalid As Boolean = false
            If (o Is Nothing) Then
                IsInvalid = true
            End If
            If (Convert.IsDBNull(o) = true) Then
                IsInvalid = true
            End If
            If (IsInvalid = true) Then
                Return false
            Else
                Return Convert.ToBoolean(o)
            End If
        End Function
        
        Shared Function NullToGuid(ByVal o As Object) As System.Guid
            Dim IsInvalid As Boolean = false
            If (o Is Nothing) Then
                IsInvalid = true
            End If
            If (Convert.IsDBNull(o) = true) Then
                IsInvalid = true
            End If
            If (IsInvalid = true) Then
                Return Guid.NewGuid
            Else
                Return CType(o,System.Guid)
            End If
        End Function
    End Class
End Namespace

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?