How to retrieve VARBINARY values from SQL Server 2008 using VB.Net

北战南征 提交于 2019-12-02 08:43:34
    Using cn As SqlConnection = New SqlConnection("Server=.;Database=test;Trusted_Connection=True;")
        cn.Open()
        Using cmd As SqlCommand = New SqlCommand()
            cmd.Connection = cn
            Dim qry As String
            qry = String.Format("SELECT field FROM test.dbo.test")
            cmd.CommandText = qry
            cmd.CommandTimeout = 0
            Dim oFileStream As System.IO.FileStream
            oFileStream = New System.IO.FileStream("c:\bytes.txt", System.IO.FileMode.Append)
            Using myReader As SqlDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection)
                While (myReader.Read())
                    Dim data As Byte() = myReader(0)
                    oFileStream.Write(data, 0, data.Length)
                End While
                oFileStream.Close()
            End Using
        End Using
    End Using

UPDATE: here is: another example on VB.NET

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!