ExecuteDataset execution problem. RRS feed

  • Question

  • User479167866 posted

    Hello to everyone on the forums.

    I am trying to use the updatedataset method from the enterprise library 2.0 and i am having some problems with that.

    The code to do so didn't work in my app so i just created a test app to test this and i am getting the same result.

    I created a table with two fields id_up,num_up this is the procedure that handles the record updating task.

    create procedure updnum
    @idb int,
    @outi int output


    begin tran
    set @outi=8888

    Update deltb set num_up=num_up + 'text'
    where id_up=@idb

    begin try
    commit tran
    set @outi=0
    end try

    begin catch
    rollback tran
    set @outi=1
    end catch


    This is the function to update the record in my DAL.

    Public Function UpdateNumber(ByVal ds As DataSet, ByVal idNum As Short) As Short

            Dim intEstope As Integer = -1
            Dim db As Database = DatabaseFactory.CreateDatabase
            Dim dbCommand As DbCommand = db.GetStoredProcCommand("updnum")
            db.AddInParameter(dbCommand, "@idb", DbType.Int16, idNum)
            db.AddOutParameter(dbCommand, "@outi", DbType.Int16, Nothing)
            db.UpdateDataSet(ds, "numbers", Nothing, dbCommand, Nothing, UpdateBehavior.Standard)       

            intEstope = CInt(db.GetParameterValue(dbCommand, "@outi"))     

            Return intEstope

     End Function

    When i execute this i get an Exception while trying to convert the "@outi" parameter to CInt because the resulting value is DBNull which is odd considering that it's being initialized on the stored procedure with the number 8888

    I have ran the stored procedure separately and it works well, also the dataset passed has data as i have confirmed reporting its number of rows before executing the updatedatabase method.

    I don't understand well whats going on here.

    If you could give me some insight i would really appreciate it.

    Thanks again.


    Tuesday, May 11, 2010 5:36 PM

All replies

  • User-1802908944 posted

    use Int32 rather than Int16

    db.AddInParameter(dbCommand, "@idb", DbType.Int32, idNum)

    db.AddOutParameter(dbCommand, "@outi", DbType.Int32 0);         

    result = db.ExecuteNonQuery(dbCommand);
     intId = Convert.ToInt64(db.GetParameterValue(dbCommand, outi));

    try this rather than db.UpdateDataSet

    hope this will help you.

    Wednesday, May 12, 2010 1:22 AM
  • User479167866 posted

    Hi Naresh.

    Thats not exactly what i am trying to accomplish, i would like to avoid the use of a sqlcommand  to update the record this way, i would like to use explicitly the dataset, update it directly and being able to trace the success of the operation after passing it against the database with the output parameter that for some reason returns null using the enterprise library UpdateDataset method.

    I will keep looking for a way to perform this.

    Thanks a lot for your help.


    Wednesday, May 12, 2010 12:14 PM