Sqlserver
 sql >> Base de données >  >> RDS >> Sqlserver

Comment récupérer des valeurs VARBINARY à partir de SQL Server 2008 à l'aide de VB.Net

    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

MISE À JOUR : voici :un autre exemple sur VB.NET