binary data in database

A

APINewbie

Hello,

Say I have a binary(8) column in my database, how would I manually
enter data into the row?

I know its something like 0x00000000000??

Is there a chart somewhere online that you guys know of?


When I pull this data from the database to my web application, I will
have to use the long data type correct? I'm a little confused how a
int data type stores a binary value?
 
S

Stephany Young

If it was the binary representation of an int then it would be binary(4),
not binary(8).

You cannot determine how to interpret the value unless you know exactly what
it represents, so I suggest you ask the dba.
 
C

Cor Ligthert[MVP]

Stephany,

Binary is a value type name in the SQL database server.

At me it says that I only can set it to Null or otherwise to leave it as is.

Cor
 
S

Stephany Young

Of course binary is a data type in SQL Server.

Yes you can update it to NULL.

Yes you can leave it as it is.

You can also read it into an array of byte, and you can also update it by
using an array of byte.

But the data is of absolutely no value at all if you dont know how to
interpret it.

If one doesn't know that then asking the person who created the column
usually works.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


Could you give more details about your problem, it not clear from your post
what is what you want to do.

You can use ADO.net to update/assign a binary column, just use a byte[].
This is the way that images are saved in a table.


If this is not your question, then care to give more details about it.
 
N

Nicholas Paldino [.NET/C# MVP]

Well, the OP's question was how to manually enter the data into the row.

No matter the size of the field in the database, if it is binary, you
can use the hexidecimal representation of the binary array (e.g. 0x01f0 will
fill binary(2) with two bytes with a value of 1 in the first byte, 240 in
the second, etc, etc).

This string literal can be used to represent binary fields of any size
when working with T-SQL. If using .NET, then as mentioned before, a byte
array will do.
 
A

ameer

Hello,

Say I have a binary(8)columnin mydatabase, how would I manually
enter data into the row?

I know its something like 0x00000000000??

Is there a chart somewhere online that you guys know of?

When I pull this data from thedatabaseto my web application, I will
have to use the long data type correct? I'm a little confused how a
int data type stores a binary value?

Hello,

Indeed a long data type would be 8 bytes but it could also be a
double. 4 bytes would be an int data type or a float. Take care that
the column you're reading stores only 8 bytes in a cell. You could in
principle store a whole array of bytes in it. The easiest way is
probably to read the data as an array of bytes and than convert it to
the correct datatype. If you don't know whether it should be a long or
double, try both and see if the numbers make any sense. Interpreting
double precision numbers as integers most of the time gives weird
numbers in the context of what you know about the data.

Hope this helps.

Cheers Arnaki
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top