473,395 Members | 1,677 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

convert SqlBinary to Byte[]

I can easily get my byte array into the SqlBinary Sql servr field.
getting it out again is more difficult.

SqlBinary myBin = myBinaryObject; // object from SQL server field.
byte[] b= myBin ;

is not allowed.

Nov 17 '05 #1
3 12836


megan wrote:
I can easily get my byte array into the SqlBinary Sql servr field.
getting it out again is more difficult.

SqlBinary myBin = myBinaryObject; // object from SQL server field.
byte[] b= myBin ;


According to the docs, the conversion operator from SqlBinary to byte[]
is defined as 'explicit', which means you must explicitly do the cast:

byte[] b = (byte[])myBin;

"If a conversion operation can cause exceptions or lose information,
.... [it should be marked] explicit. This prevents the compiler from
silently invoking the conversion operation with possibly unforeseen
consequences."

--
Larry Lard
Replies to group please

Nov 17 '05 #2
Hi Megan,

A SqlBinary has to Byte[] Conversion static function, so
you should be able to write:
byte[] myBytes=(byte[]) myBin;
I can easily get my byte array into the SqlBinary Sql servr field.
getting it out again is more difficult.

SqlBinary myBin = myBinaryObject; // object from SQL server field.
byte[] b= myBin ;

is not allowed.


It's not allowed, because C# is type safe language.
And that is a realy good thing.

Cheers & HTH
Marcin
Nov 17 '05 #3
YAY!! Thanks very much everybody.

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: jeff | last post by:
how do you convert form byte to Int32 while retaining the binary value of the byte array
14
by: Chris | last post by:
Hi, I try to print out truth-tables for an &&-operation using the following code, unfortunatly I get compiler errors : for ( byte i1=0; i1<=1; i1++) { for ( byte i2=0; i2<=1; i2++) { bool...
6
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
15
by: Kueishiong Tu | last post by:
How do I convert a Byte array (unsigned char managed) to a char array(unmanaged) with wide character taken into account?
2
by: Imran Aziz | last post by:
Hello All, How can I convert System.Byte to System.String ? When I use Convert.ToString() it just returns me the string "System.Byte" Please help me out with this. Imran.
4
by: Dean Slindee | last post by:
I have a timestamp field that I would like to display in a textbox. The timestamp is an 8 byte array. Can this be converted to a string in one statement or does it require cycling thru one byte...
8
by: Serge BRIC | last post by:
My application, written in .NET VB, tries to get a communication port handle from a TAPI object with this code: Dim vFileHandle As Byte() = appel.GetIDAsVariant("comm/datamodem") The...
3
by: efdeugenio | last post by:
Hi, I will really appreciate if someone cans help me with this: I have a managed c++ class that I am calling from C#. The declaration of a function in this class is: bool CanAddTemplate(unsigned...
4
by: Pramod | last post by:
Hi. I have a C++ method which accepts - byte* - and I am calling this method from a C# application. I have created a byte to pass by ref. This is how I call the C++ method: Method(ref...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.