Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 14th, 2004, 10:02 AM
Authorized User
 
Join Date: Nov 2003
Location: , , Mexico.
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.


Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:19 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.