Updating the Database Wrapper for C#

by Sameera 19. June 2008 04:52

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

10/13/2008 12:59:43 PM #

Yordan Georgiev

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

Yordan Georgiev

Add comment


(Will show your Gravatar icon)

biuquote
  • Comment
  • Preview
Loading



About Me

Sameera Perera

Sameera Perera

  • Solutions Architect
  • View Sameera Perera's profile on LinkedIn

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

Disclaimer

This is a personal blog. The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

All forms of source code published on Codoxide.com are distributed under the Apache License, Version 2.0 unless otherwise stated.
The rest of the content are published under a Creative Commons Attribution 3.0 License.
Creative Commons License