本文整理汇总了VB.NET中System.Data.DataTableReader.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:VB.NET DataTableReader.GetBytes方法的具体用法?VB.NET DataTableReader.GetBytes怎么用?VB.NET DataTableReader.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了DataTableReader.GetBytes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: Module1
' 导入命名空间
Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing
Imports System.IO
Imports System.Drawing.Imaging
Module Module1
Sub Main()
TestGetBytes()
End Sub
Private Sub TestGetBytes()
' Set up the data adapter, using information from
' the AdventureWorks sample database.
Dim photoAdapter As SqlDataAdapter = _
SetupDataAdapter("SELECT ThumbnailPhotoFileName, " & _
"ThumbNailPhoto FROM Production.ProductPhoto")
' Fill the DataTable.
Dim photoDataTable As New DataTable
photoAdapter.Fill(photoDataTable)
' Create the DataTableReader.
Using reader As DataTableReader = New DataTableReader(photoDataTable)
Dim buffer() As Byte
Dim productName As String
While reader.Read()
Try
' Get the name of the file.
productName = reader.GetString(0)
' Get the length of the field. Pass Nothing
' in the buffer parameter to retrieve the length
' of the data field. Ensure that the field isn't
' null before continuing.
If reader.IsDBNull(1) Then
Console.WriteLine( _
productName & " is unavailable.")
Else
' Retrieve the length of the necessary byte array.
Dim len As Long = reader.GetBytes(1, 0, Nothing, 0, 0)
' Create a buffer to hold the bytes, and then
' read the bytes from the DataTableReader.
ReDim buffer(CInt(len))
reader.GetBytes(1, 0, buffer, 0, CInt(len))
' Create a new Bitmap object, passing the array
' of bytes to the constructor of a MemoryStream.
Using productImage As New Bitmap(New MemoryStream(buffer))
Dim fileName As String = "C:\" & productName
' Save in gif format.
productImage.Save( _
fileName, ImageFormat.Gif)
Console.WriteLine("Successfully created " & _
fileName)
End Using
End If
Catch ex As Exception
Console.WriteLine(productName & ": " & _
ex.Message)
End Try
End While
End Using
Console.WriteLine("Press Enter to finish.")
Console.ReadLine()
End Sub
Private Function SetupDataAdapter( _
ByVal sqlString As String) As SqlDataAdapter
' Assuming all the default settings, create a SqlDataAdapter
' working with the AdventureWorks sample database that's
' available with SQL Server.
Dim connectionString As String = _
"Data Source=(local);" & _
"Initial Catalog=AdventureWorks;" & _
"Integrated Security=true"
Return New SqlDataAdapter(sqlString, connectionString)
End Function
End Module
开发者ID:VB.NET开发者,项目名称:System.Data,代码行数:80,代码来源:DataTableReader.GetBytes
注:本文中的System.Data.DataTableReader.GetBytes方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论