none
returning dataset empty with DAAB RRS feed

  • Question

  • Hi Everybody,

     

    I am with a strange problem. Below I send my c# code and a simple stored procedure code. I am running Visual C# 2008 Express and SQL Server 2005 Express, using Data Access Application Block of Enterprise Library 4.

     

    With this configuration, I did´t find a way to return a dataset with default table filled. Is there anything wrong with my code ? Those 3 options return an empty dataset.

     

    My code - 1st option

    ================

    Database database = DatabaseFactory.CreateDatabase("SqlServer");
    DbCommand command = database.GetStoredProcCommand("SELECT_PRODUCT");

    database.AddInParameter(command, "@CD_PRODUCT", DbType.Int64, 1);
    database.AddOutParameter(command, "@NM_PRODUCT", DbType.String, 50);

    return database.ExecuteDataSet(command);

     

    My code - 2nd option

    =================

    Database database = DatabaseFactory.CreateDatabase("SqlServer");
    DbCommand command = database.GetStoredProcCommand("SELECT_PRODUCT");

    database.AddInParameter(command, "@CD_PRODUCT", DbType.Int64, 1);
    database.AddOutParameter(command, "@NM_PRODUCT", DbType.String, 50);

    DataSet dataset = new DataSet();

    database.LoadDataSet(command, dataset, "PRODUCT");

    return dataset;

     

    My code - 3nd option

    =================

    Database database = DatabaseFactory.CreateDatabase("SqlServer");
    SqlCommand command = database.GetStoredProcCommand("SELECT_PRODUCT");

    database.AddInParameter(command, "@CD_PRODUCT", SqlDbType.Int, 1);
    database.AddOutParameter(command, "@NM_PRODUCT", SqlDbType.VarChar, 50);

    DataSet dataset = new DataSet();

    database.LoadDataSet(command, dataset, "PRODUCT");

    return dataset;

     

    Stored Procedure

    =============

    CREATE PROCEDURE [dbo].[SELECT_PRODUCT]
     @CD_PRODUCT BIGINT,
     @NM_PRODUCT VARCHAR(50) OUTPUT
    AS
    BEGIN
     SELECT @NM_PRODUCT = NM_PRODUCT FROM PRODUCT WHERE CD_PRODUCT = @CD_PRODUCT
    END

     

    The stored procedure is ok, because when i run it directly in my database it returns the name of a product.

     

    Thanks for any help !

    Sunday, November 2, 2008 12:37 PM

All replies

  • Your stored procedure does not return DataSet, it returns value as a return parameter and you need to read this parameter after call to the database was executed

    Monday, November 3, 2008 8:16 PM
    Moderator