Hi Vinod,
Thanks for posting in the community! My name is Steven, and I'll be
assisting you on this issue.
From your description, you used ADO.NET component to execute a stored
procedure and the sp has a parameter whose type is varbinary. And you want
to set a certain string as the value of the parameter.
If there is anything I misunderstood, please feel free to let me know.
As for this problem, I quite agree to Hermit's suggestion. The
"SqlDbType.VarBinary" is mapped to the a byte array(byte[] in c#). So you
need to transmit a byte array as the value of the certain sp's paramter.
Considering that the original object you want store into the
"SqlDbType.VarBinary" type column is a string, I think you need to first
convert the string into a byte[] just as Hermit mentioned:
For example, using
byte[] barr = System.Text.Encoding.Unicode.GetBytes( stringobject );
then, add this byte[] as the stored procedure's VarBinary parameter.
Also, when you retrieve the VarBinary column data out from the database and
set into a byte[], again you need to convert the byte[] back to string so
as for further use:
string output = System.Text.Encoding.Unicode.GetString(bytearrary);
In addtion, I've searched some references and tech articles on programing
with binray data types using ADO.NET and stored procudure:
#How to read and write a file to or from a BLOB column by using ADO.NET and
Visual C# .NET
http://support.microsoft.com/default.aspx?scid=kb;en-us;317016
#HOW TO: Copy a Picture from a Database Directly to a PictureBox Control
with Visual C#
http://support.microsoft.com/?id=317701
Reference on the System.Text.Encoding class's GetBytes and GetString method:
#Encoding.GetBytes Method
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemTextEncodingCl
assGetBytesTopic.asp?frame=true
#Encoding.GetString Method
http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemTextEncodingCl
assGetStringTopic.asp?frame=true
Please check them out if you feel needed. If you have any further
questions, please feel free to post here.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)