sampleuda.vb
来自「wrox出版社的另一套经典的VB2005数据库编程学习书籍,收集了书中源码,郑重」· VB 代码 · 共 64 行
VB
64 行
Option Explicit On
Option Strict On
Imports System
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlTypes
Imports Microsoft.SqlServer.Server
'Added
Imports System.Text
Imports System.IO
<Serializable()> _
<SqlUserDefinedAggregate(Format.UserDefined, IsInvariantToDuplicates:=False, IsInvariantToNulls:=True, _
IsInvariantToOrder:=False, IsNullIfEmpty:=True, MaxByteSize:=8000)> _
Public Class CSVStringUDA
Implements IBinarySerialize
Private sbCSV As StringBuilder
Public Sub Init()
'Initialize with an opening "
sbCSV = New StringBuilder()
sbCSV.Append(ControlChars.Quote)
End Sub
Public Sub Accumulate(ByVal sqlString As SqlString)
If (sqlString.IsNull) Then
Return
Else
'Append the separator + ","
sbCSV.Append(sqlString.Value).Append(""",""")
End If
End Sub
Public Sub Merge(ByVal csvString As CSVStringUDA)
'Merge the current instance with the another thread's instance, if present
sbCSV.Append(csvString.sbCSV)
End Sub
Public Function Terminate() As SqlString
'Return the string from the StringBuilder or an empty string
If sbCSV.Length > 0 Then
sbCSV.Append(vbCrLf)
Return New SqlString(sbCSV.ToString(0, sbCSV.Length - 4))
Else
Return New SqlString("")
End If
End Function
Public Sub Read(ByVal brCSV As System.IO.BinaryReader) Implements IBinarySerialize.Read
'Format.UserDefined, so a BinaryReader is required
sbCSV = New StringBuilder(brCSV.ReadString())
End Sub
Public Sub Write(ByVal bwCSV As System.IO.BinaryWriter) Implements IBinarySerialize.Write
'Format.UserDefined, so a BinaryWriter is required
bwCSV.Write(sbCSV.ToString())
End Sub
End Class
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?