Re: Retrieve varbinary from SqlServer using OUTPUT params in Store

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Alvin wrote:

> How do I do that in C#. There is a typo in the Proc declaration. The
> output param is indeed declared as varbinary(100)

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


>
> Thanks
>
> "Frans Bouma [C# MVP]" wrote:
>
> > Alvin wrote:
> >
> > > 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
> >
> > Shouldn't you declare your parameter in the proc as 'varbinary(100)
> > and the parameter in the C# code as SqlDBType.VarBinary ?


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



Relevant Pages

  • DBD::Sybase question
    ... Sybase ASE 12.5 server. ... I'm using preparewith placeholders and OUTPUT ... which is an output param also bound with bind_param. ... Then I call a third proc that takes 5 input ...
    (perl.dbi.users)
  • How to retrieve an Output Parameter using SQLDataSource Control
    ... I am trying to call a insert proc using the SQLDatasource Control. ... able to call the insert just fine, but when I added an output param, I got ... Jeff V ...
    (microsoft.public.dotnet.framework.aspnet)