Re: Retrieve varbinary from SqlServer using OUTPUT params in Store
- From: "Frans Bouma [C# MVP]" <perseus.usenetNOSPAM@xxxxxxxxx>
- Date: Fri, 02 Dec 2005 01:50:08 -0800
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#)
------------------------------------------------------------------------
.
- References:
- Re: Retrieve varbinary from SqlServer using OUTPUT params in StoredPro
- From: Frans Bouma [C# MVP]
- Re: Retrieve varbinary from SqlServer using OUTPUT params in StoredPro
- Prev by Date: Re: VS2005, ADO.NET 2.0 How to build a typed data set based on and oracle stord procedure?
- Next by Date: Multiple dataTables in dataset, insert problem
- Previous by thread: Re: Retrieve varbinary from SqlServer using OUTPUT params in StoredPro
- Next by thread: Re: Insert Unicode string
- Index(es):
Relevant Pages
|