Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using a StoreProcedure to update multiple records.
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01469120
Message ID:
01469235
Views:
42
Maybe needs:
comm.CommandType=CommandType.StoredProcedure;
>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!
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform