sampleudt.vb

来自「wrox出版社的另一套经典的VB2005数据库编程学习书籍,收集了书中源码,郑重」· VB 代码 · 共 83 行

VB
83
字号
Option Explicit On
Option Strict On

Imports System
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server

<Serializable()> _
<Microsoft.SqlServer.Server.SqlUserDefinedType(Format.Native)> _
    Public Structure PointUDT
    Implements INullable

    Private blnIsNull As Boolean
    'Coordinates
    Private dblX As Double
    Private dblY As Double

    Public ReadOnly Property IsNull() As Boolean _
      Implements INullable.IsNull
        'Required
        Get
            Return blnIsNull
        End Get
    End Property

    Public Shared ReadOnly Property Null() As PointUDT
        'Required
        Get
            Dim ptNew As PointUDT
            ptNew.blnIsNull = True
            Return ptNew
        End Get
    End Property

    Public Overrides Function ToString() As String
        'Return the comma-separated values
        If Me.IsNull Then
            Return "Null"
        Else
            Return Me.dblX.ToString + "," + Me.dblY.ToString
        End If
    End Function

    Public Shared Function Parse(ByVal sqlString As SqlString) As PointUDT
        'Creates a PointUDT by splitting an input string at the separator character
        If sqlString.IsNull Then
            Return Nothing
        Else
            Dim ptNew As PointUDT
            Dim strNew As String = sqlString.ToString
            Dim astrXY() As String = strNew.Split(","c)
            ptNew.X = CType(astrXY(0), Double)
            ptNew.Y = CType(astrXY(1), Double)
            Return ptNew
        End If
    End Function

    Public Property X() As Double
        'X-coordinate
        Get
            Return Me.dblX
        End Get
        Set(ByVal Value As Double)
            Me.dblX = Value
            blnIsNull = False
        End Set
    End Property

    Public Property Y() As Double
        'Y-coordinate
        Get
            Return Me.dblY
        End Get
        Set(ByVal Value As Double)
            Me.dblY = Value
            blnIsNull = False
        End Set
    End Property
End Structure

⌨️ 快捷键说明

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