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.

One thought on “Updating the Database Wrapper for C#

  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 
                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  
                    //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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.