Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using a StoreProcedure to update multiple records.
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01469120
Message ID:
01469230
Vues:
32
Here de full C# code:
public static bool Update_idEstadoPrestamo(int idPrestamoSeleccionado, int idNuevoEstado)
    {
        DbCommand comm = GenericDataAccess.CreateCommand();
        comm.CommandText = "stp_xsarcprestamos_UPDATEIdEstado";

        DbParameter param = comm.CreateParameter();
        param.ParameterName = "@idPrestamo";
        param.Value = idPrestamoSeleccionado;
        param.DbType = DbType.Int32;
        comm.Parameters.Add(param);

        param = comm.CreateParameter();
        param.ParameterName = "@idNuevoEstado";
        param.Value = idNuevoEstado;
        param.DbType = DbType.Int32;
        comm.Parameters.Add(param);

        param = comm.CreateParameter();
        param.ParameterName = "@AffectedRows";
        param.Value = 0;
        param.DbType = DbType.Int32;
        param.Direction = ParameterDirection.Output;
        comm.Parameters.Add(param);

        int success = -1;
        try
        {
            success = GenericDataAccess.ExecuteNonQuery(comm);
        }
        catch
        { //any errors are logged in GenericDataAccess...
        }
        return (success != -1);
    }
public static int ExecuteNonQuery(DbCommand command)
    {
        //the number of affected rows.
        int affectedRows = -1;

        //execute the command making sure the connection gets closed in the end.
        try
        {
            //open the connecction of the command
            command.Connection.Open();

            //execute the command and get the number of affected rows.
            affectedRows = command.ExecuteNonQuery();            
        }
        catch (Exception ex)
        {
            //log eventual error and rethrow them.
            //Utilities.LogError(ex); 
            MessageBox.Show(ex.Message, "Excepción Inexperada", MessageBoxButtons.OK, MessageBoxIcon.Information);
            throw ex;
        }
        finally
        {
            //close the connection
            command.Connection.Close();
        }
        //return the number of affected rows.
        return affectedRows;
    }
Thanks for your help!
William Chavez
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform