Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 14th, 2004, 10:02 AM
Authorized User
 
Join Date: Nov 2003
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default OUTPUT Parameters

Hi everybody

I have a Stored procedure(SyBase 12.5) that returns a OUTPUT value, but it always returns a DBNull. I test the SP in other application (DBArtisan like a Query Analizer) and it returns the correct value, but when I test in my NET application (made in C#) it returns DBNull. If I try to make a cast I get the exception "Object cannot be cast from DBNull to other types"

This is my code my SP:

CREATE PROCEDURE dbo.sp_Prueba(
                 @vsTransId char(4),
                 @vsContratoId varchar(4),
          @vsLoginUser varchar(40),
         @vsParamList varchar(200),
         @iResp int OUTPUT
                              )
AS
    Declare @iError int
    Declare @OK int

    BEGIN

       Select @iError = 0
       Select @OK = 0

       BEGIN TRAN Pruebas

        Insert into LogTransacc
            Values (@vsTransId,@vsContratoId,@vsLoginUser,"Pruebas Juan",@vsParamList,"Ini",getdate())

            Select @iError = @@error

        if(@iError = @OK)
        Begin
          Select @iResp = @OK
          COMMIT TRAN Pruebas
        End
        else
        Begin
          Select @iResp = @iError
          ROLLBACK TRAN Pruebas
        End

    END

And this my function:

    private void Insertar() {
        string strcadena = cadenaConn;
        OleDbConnection oleConn = null;
        try {
            oleConn = new OleDbConnection(strcadena);
            oleConn.Open();

            OleDbCommand oleCmmd = new OleDbCommand();

            oleCmmd.CommandType = CommandType.StoredProcedure;
            oleCmmd.Connection = oleConn;
            oleCmmd.CommandText = "sp_Prueba";

            oleCmmd.Parameters.Add("@vsTransId",OleDbType.Char ,4);
            oleCmmd.Parameters["@vsTransId"].Value = "9500";

            oleCmmd.Parameters.Add("@vsContratoId",OleDbType.V arChar,4);
            oleCmmd.Parameters["@vsContratoId"].Value = "0000";

            oleCmmd.Parameters.Add("@vsLoginUser",OleDbType.Va rChar,40);
            oleCmmd.Parameters["@vsLoginUser"].Value = "Juan Carlos Gonzalez";

            oleCmmd.Parameters.Add("@vsParamList",OleDbType.Va rChar,200);
            oleCmmd.Parameters["@vsParamList"].Value = "Esta es una prueba para insertar utilizando Threads";

            oleCmmd.Parameters.Add("@iResp", OleDbType.Integer);
            oleCmmd.Parameters["@iResp"].Direction = ParameterDirection.Output;

            oleCmmd.ExecuteNonQuery();

            if(oleCmmd.Parameters["@iResp"].Value.Equals(System.DBNull.Value))
                 MessageBox.Show("OUTPUT Null");

                        else
                             MessageBox.Show("OUTPUT Not null");

            oleCmmd.Dispose();

        }
        catch(Exception Ex) {
            Console.WriteLine(Ex.Message);
        }
        finally {
            if(oleConn != null) {
                if(oleConn.State != System.Data.ConnectionState.Closed)
                    oleConn.Close();
            }
        }
}

Does someone help me, please?

Regards
J.C.







Similar Threads
Thread Thread Starter Forum Replies Last Post
Output Parameters: I can't be this stupid... raysot BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 13 May 20th, 2010 07:28 PM
Chapter 6 "Using SQL Output Parameters..." burkecrosby BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 22 February 10th, 2010 05:33 PM
output parameters with the objectdatasource trancehead ASP.NET 2.0 Professional 2 August 25th, 2008 12:41 PM
Output Parameters Bob Bedell SQL Server 2000 2 March 25th, 2006 06:32 AM
SQL output parameters ohiggs SQL Server 2000 4 February 9th, 2004 10:09 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.