2008-10-23 3 views
1

이 상황이 있습니다. SQL 2005 데이터베이스의 varbinary 필드에 실제 데이터가 저장되어 있습니다. SQL 2005에서 varbinary를 real로 변환 할 수 없기 때문에 vb.net에서이를 수행하려고합니다.VB.Net에서 byte() 배열을 double로 변환합니다.

해당 필드는 DataTable에 byte() 배열로 저장됩니다.

이제 double()을 double 또는 decimal 변수로 읽고 싶습니다. 하지만 그 방법에 대한 단서는 많이 없습니다 ...

답변

2

정말 저장 방법에 따라 달라 지지만, BitConverter.ToDouble은 친구 일 수 있습니다. 그것은 IEE754 형식으로 가정합니다. 처음부터 데이터를 어디에서 가져 왔습니까?

1

저는 VB.net을 잘 모르지만 .NET 라이브러리를 알고 있습니다.

byte []를 MemoryStream에 랩핑하고 BinaryReader에 랩핑합니다. 그런 다음 BinaryReader.ReadDouble() 메서드를 사용합니다. MSDN 페이지의 경우 herehere을 참조하십시오. this

에 응답

편집이처럼 보이는 코드의 조각을 찾고 있습니다 :

'declare a test array 
Dim testArray As Byte() = {0, 0, 0, 0} 
'wrap it into a memory stream 
Dim memStream As MemoryStream = new MemoryStream(testArray) 
'wrap the stream in a binary reader 
Dim bReader As BinaryReader = new BinaryReader(memStream) 
'read a 32bit integer from the stream using the reader 
Dim count As Integer = bReader.ReadInt32() 
0
Public Function GetDateFromBytes(ByRef value() As Byte, _ 
            ByRef startindex As Int32) As Date 
    'create a aray of Ints 
    Dim IntValues() As Int32 = {BitConverter.ToInt32(value, startindex), _ 
            BitConverter.ToInt32(value, (startindex + 7)), _ 
            BitConverter.ToInt32(value, startindex + 15), _ 
            BitConverter.ToInt32(value, startindex + 31)} 

    Return Date.FromBinary(New Decimal(IntValues)) 

End Function 
+1

죄송합니다, 내 이전을. 코드가 잘못되었습니다. 여기 아래가 올바른 것입니다. –

관련 문제