本文整理汇总了VB.NET中System.Data.DataTableReader.GetChars方法的典型用法代码示例。如果您正苦于以下问题:VB.NET DataTableReader.GetChars方法的具体用法?VB.NET DataTableReader.GetChars怎么用?VB.NET DataTableReader.GetChars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了DataTableReader.GetChars方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Module1
' 导入命名空间
Imports System.Data
Imports System.IO
Module Module1
Private Sub TestGetChars( _
ByVal reader As DataTableReader, ByVal bufferSize As Integer)
' The filename is in column 0, and the contents are in column 1.
Const FILENAME_COLUMN As Integer = 0
Const DATA_COLUMN As Integer = 1
Dim buffer() As Char
Dim offset As Integer
Dim charsRead As Integer
Dim fileName As String
Dim currentBufferSize As Integer
While reader.Read
' Reinitialize the buffer size and the buffer itself.
currentBufferSize = bufferSize
ReDim buffer(bufferSize - 1)
' For each row, write the data to the specified file.
' First, verify that the FileName column isn't null.
If Not reader.IsDBNull(FILENAME_COLUMN) Then
' Get the file name, and create a file with
' the supplied name.
fileName = reader.GetString(FILENAME_COLUMN)
' Start at the beginning.
offset = 0
Using outputStream As New StreamWriter(fileName, False)
Try
' Loop through all the characters in the input field,
' incrementing the offset for the next time. If this
' pass through the loop reads characters, write them to
' the output stream.
Do
charsRead = Cint(reader.GetChars(DATA_COLUMN, offset, _
buffer, 0, bufferSize))
If charsRead > 0 Then
outputStream.Write(buffer, 0, charsRead)
offset += charsRead
End If
Loop While charsRead > 0
Catch ex As Exception
Console.WriteLine(fileName & ": " & ex.Message)
End Try
End Using
End If
End While
Console.WriteLine("Press Enter key to finish.")
Console.ReadLine()
End Sub
Sub Main()
Dim table As New DataTable
table.Columns.Add("FileName", GetType(System.String))
table.Columns.Add("Data", GetType(System.Char()))
table.Rows.Add("File1.txt", "0123456789ABCDEF".ToCharArray)
table.Rows.Add("File2.txt", "0123456789ABCDEF".ToCharArray)
Dim reader As New DataTableReader(table)
TestGetChars(reader, 7)
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System.Data,代码行数:71,代码来源:DataTableReader.GetChars
注:本文中的System.Data.DataTableReader.GetChars方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论