Retrieving a byte array from an access database

  • Thread starter Thread starter Nak
  • Start date Start date
N

Nak

Hi there,

I'm sure this is pretty easy but I seem to be having problems, I have a
database that contains some binary data in some of the fields. As a test a
made this 2 bytes long with lets say "11" as it's contents (ASCII "1" &
"1"). Now when it comes to retrieving the data I am using this line of code

Call pDBRReader.GetBytes(5, 0, mybytearray, 0, Integer.MaxValue)

"pDBRReader is an OleDbDataReader"
"5 is the column in which the data resides"

I am not getting any exceptions thrown and the return value from this
line is 2, yet mybytearray is still Nothing, any ideas?? Cheers in
advance!!!!!

Nick.
 
Hi Nick,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that the buffer is still nothing when you
have called GetBytes. If there is any misunderstanding, please feel free to
let me know.

Based on your description, I think you didn't set the buffer mybytearray to
a valid object reference. We have to initialize it first before calling
GetBytes. Here is an example:

mybytearray = new Byte[Integer.MaxValue];
pDBRReader.GetBytes(5, 0, mybytearray, 0, Integer.MaxValue)

Based on the MSDN document, if you pass a buffer that is a null reference
(Nothing in Visual Basic), GetBytes returns the length of the field in
bytes without throwing any exception.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi Kevin,

Thanks for the help, as you rightly suggested, I was passing a null
reference to the function thinking it would resize the array as necessary.
Cheers!

Nick.
 
Hi Kevin,

Unfortunately even after trying as you have suggested I am still being
given a null reference back. I have tried a few variations of initialising
the byte array first of all, i.e. via Redim and New keywords but still no
luck when I try to access the returned data. Any ideas?

Nick.

Nak said:
Hi Kevin,

Thanks for the help, as you rightly suggested, I was passing a null
reference to the function thinking it would resize the array as necessary.
Cheers!

Nick.

Kevin Yu said:
Hi Nick,

First of all, I would like to confirm my understanding of your issue.
From
your description, I understand that the buffer is still nothing when you
have called GetBytes. If there is any misunderstanding, please feel free
to
let me know.

Based on your description, I think you didn't set the buffer mybytearray
to
a valid object reference. We have to initialize it first before calling
GetBytes. Here is an example:

mybytearray = new Byte[Integer.MaxValue];
pDBRReader.GetBytes(5, 0, mybytearray, 0, Integer.MaxValue)

Based on the MSDN document, if you pass a buffer that is a null reference
(Nothing in Visual Basic), GetBytes returns the length of the field in
bytes without throwing any exception.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Hi again....

I've sussed it now, the array needs to be initialised at the *correct*
length before passing it to the routine. Pants!

Nick.

Nak said:
Hi Kevin,

Thanks for the help, as you rightly suggested, I was passing a null
reference to the function thinking it would resize the array as necessary.
Cheers!

Nick.

Kevin Yu said:
Hi Nick,

First of all, I would like to confirm my understanding of your issue.
From
your description, I understand that the buffer is still nothing when you
have called GetBytes. If there is any misunderstanding, please feel free
to
let me know.

Based on your description, I think you didn't set the buffer mybytearray
to
a valid object reference. We have to initialize it first before calling
GetBytes. Here is an example:

mybytearray = new Byte[Integer.MaxValue];
pDBRReader.GetBytes(5, 0, mybytearray, 0, Integer.MaxValue)

Based on the MSDN document, if you pass a buffer that is a null reference
(Nothing in Visual Basic), GetBytes returns the length of the field in
bytes without throwing any exception.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top