Codoxide
19Jun/081

Updating the Database Wrapper for C#

I have made a few updates for my Generic Database Wrapper class. The update contains a bug fix along with several additional methods for supporting DbParameters.

The new source file can be downloaded here. I have also updated the file linked to the original post.

Comments (1) Trackbacks (0)
  1. Might be obvious for many , but herewith an example of how-to call stored procedure . I spent couple of hours figuring out how-to get out parameters correctly …

    public bool UpdateProject(string procedureName , ref string msg, string domainName,
    string projectId , string prsUser , string prsPassword )

    {
    int ret = 1 ; //assume false

    try
    {

    using (Database db = new Database(_ConnectionString))
    {
    //create command with the procedure name
    DbCommand cmd = db.GetStoredProcedureCommand(procedureName);

    //add here in parameters
    db.AddInParameter(cmd,"@domain_user", DbType.String, (object)domainName);
    db.AddInParameter(cmd, "@project_id", DbType.Int16, (object)projectId);
    //add out parameters
    db.AddInOutParameter(cmd, "@msg", DbType.String, (object)msg);
    db.AddInOutParameter(cmd, "@ret", DbType.Int16, (object)ret);

    //execute the actual procedure
    db.ExecuteNonQuery(cmd);

    //get the output parameter values from the procedure
    ret = Int32.Parse( cmd.Parameters[ "@ret" ].Value.ToString());
    msg = cmd.Parameters[ "@msg" ].Value.ToString();

    //returns true if ret == 0 and false if ret == 1
    return !System.Convert.ToBoolean((int)ret);

    } //eof using
    } //eof try
    catch (Exception e)
    {
    msg = "An error in the application occurred. Report the following error code:mlcv1" + e.Message;
    return false;
    } //eof catch
    } //eof method


Leave a comment

No trackbacks yet.