all groups > dotnet ado.net > november 2005 >
You're in the

dotnet ado.net

group:

Retrieve varbinary from SqlServer using OUTPUT params in StoredPro


Retrieve varbinary from SqlServer using OUTPUT params in StoredPro Alvin
11/30/2005 12:58:09 PM
dotnet ado.net:
Hi

I have a stored proc with a varbinary OUTPUT param and I am trying to
retrieve the value of this variable in the C# using SqlCommand and setting
its parameters. However, I am not able to retrieve the value of varbinary
variable in C# for some unknown reasons. I would really appreciate your help.
Thanks

Alvin


Byte [] testBinary = new Byte[100];
SqlParameter param1 = SqlCommand,Parameters.Add("@testBinary",
SqlDBType.Binary, 100);
param1.value = testBinary
SqlCommand.CommandType = CommandType.StoredProcedure
SqlCommand.Direction = ParameterDirection.Output
SqlCommand.ExecureNonQuery()
Console.Writeline("Output param is {0}", Convert.ToBase64(testBinary));
====> Don't see the value from Stored Proc

StoredProc
CREATE PROCEDURE test
testBinary (100) OUTPUT
AS
BEGIN
select @testBinary = testbin from testTable
END

Re: Retrieve varbinary from SqlServer using OUTPUT params in StoredPro Frans Bouma [C# MVP]
12/1/2005 1:42:28 AM
[quoted text, click to view]

Shouldn't you declare your parameter in the proc as 'varbinary(100)
and the parameter in the C# code as SqlDBType.VarBinary ?

FB


--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
Re: Retrieve varbinary from SqlServer using OUTPUT params in Store Alvin
12/1/2005 9:11:03 AM
How do I do that in C#. There is a typo in the Proc declaration. The output
param is indeed declared as varbinary(100)

Thanks

[quoted text, click to view]
Re: Retrieve varbinary from SqlServer using OUTPUT params in Store Frans Bouma [C# MVP]
12/2/2005 1:50:08 AM
[quoted text, click to view]

change:
SqlParameter param1 = SqlCommand,Parameters.Add("@testBinary",
SqlDBType.Binary, 100);

in:
SqlParameter param1 = SqlCommand,Parameters.Add("@testBinary",
SqlDBType.VarBinary, 100);

The rest of the code seems to be ok, though what I'd do for testing
first is to see if the byte array does contain a value or not before
using base64

FB


[quoted text, click to view]


--
------------------------------------------------------------------------
Get LLBLGen Pro, productive O/R mapping for .NET: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
AddThis Social Bookmark Button