Jon Skeet, it doesn't work...
biozinc, I'm trying to do as you say but I'm getting a
"Unable to read beyond the end of the stream" exception.
This is my code:
Dim con As SqlConnection = New SqlConnection("Server=OMNILOGADMIN-PC;Database=master;Trusted_Connection=True;")
Dim cmd As SqlCommand = New SqlCommand()
Dim da As SqlDataAdapter = New SqlDataAdapter()
Dim dt As DataTable = New DataTable()
Dim ba As Byte()
Dim val As Decimal
Dim memStream As MemoryStream = New MemoryStream()
Dim bReader As BinaryReader
cmd.CommandText = "select convert(varbinary(max), cast(500 as real)) val"
cmd.Connection = con
da.SelectCommand = cmd
Try
con.Open()
da.Fill(dt)
ba = dt.Rows(0).Item(0)
'val = BitConverter.ToDouble(ba, 0)
memStream.Write(ba, 0, ba.Length)
MessageBox.Show( _
memStream.Capacity.ToString() & vbCrLf & _
memStream.Length.ToString() & vbCrLf & _
memStream.Position.ToString())
bReader = New BinaryReader(memStream)
memStream.Seek(0, SeekOrigin.Begin)
Dim testArray As Byte() = {0, 0, 0, 0}
Dim count As Integer = bReader.Read(testArray, 0, 3)
MessageBox.Show(count & " - " & bReader.ReadDecimal())
Catch ex As Exception
MessageBox.Show("Erro: " & vbCrLf & ex.Message)
Finally
con.Close()
End Try
Any clues/sugestions?
thanks a lot!