Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. IDataAccessLayer

IDataAccessLayer

Scheduled Pinned Locked Moved The Weird and The Wonderful
learning
5 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    ColinBashBash
    wrote on last edited by
    #1

    ugh. if only we all understood how static works... and perhaps naming conventions... hmm, i guess understanding when to apply the word "static" to a class might also be helpful... i don't even care about the bad use of List<SqlParameter>. Oh and don't worry, there were comments for the functions, the class, the property, and of course i didn't remove the one inside the constructor...

    public class IDataAccesslayer
    {
    private static SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["connStr"].ToString());

    public IDataAccesslayer()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    
    public static void ExecuteNoReturn(String spName, List<SqlParameter> parms)
    {
        try
        {
            conn.Open();
    
            SqlCommand cmd = new SqlCommand(spName, conn);
            cmd.CommandType = CommandType.StoredProcedure;
    
            foreach (SqlParameter parm in parms)
            {
                cmd.Parameters.Add(parm);
            }
    
            cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            throw (ex);
        }
        finally
        {
            if (conn.State == ConnectionState.Open)
                conn.Close();
        }
    }
    public static DataSet ExecuteReturnDataSet(String spName, List<SqlParameter> parms)
    {
        //this was same as previous, except using a data-adapter
    }
    

    }

    G J _ 3 Replies Last reply
    0
    • C ColinBashBash

      ugh. if only we all understood how static works... and perhaps naming conventions... hmm, i guess understanding when to apply the word "static" to a class might also be helpful... i don't even care about the bad use of List<SqlParameter>. Oh and don't worry, there were comments for the functions, the class, the property, and of course i didn't remove the one inside the constructor...

      public class IDataAccesslayer
      {
      private static SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["connStr"].ToString());

      public IDataAccesslayer()
      {
          //
          // TODO: Add constructor logic here
          //
      }
      
      public static void ExecuteNoReturn(String spName, List<SqlParameter> parms)
      {
          try
          {
              conn.Open();
      
              SqlCommand cmd = new SqlCommand(spName, conn);
              cmd.CommandType = CommandType.StoredProcedure;
      
              foreach (SqlParameter parm in parms)
              {
                  cmd.Parameters.Add(parm);
              }
      
              cmd.ExecuteNonQuery();
          }
          catch (Exception ex)
          {
              throw (ex);
          }
          finally
          {
              if (conn.State == ConnectionState.Open)
                  conn.Close();
          }
      }
      public static DataSet ExecuteReturnDataSet(String spName, List<SqlParameter> parms)
      {
          //this was same as previous, except using a data-adapter
      }
      

      }

      G Offline
      G Offline
      GibbleCH
      wrote on last edited by
      #2

      Don't forget the abomination that is

      throw (ex);

      P 1 Reply Last reply
      0
      • C ColinBashBash

        ugh. if only we all understood how static works... and perhaps naming conventions... hmm, i guess understanding when to apply the word "static" to a class might also be helpful... i don't even care about the bad use of List<SqlParameter>. Oh and don't worry, there were comments for the functions, the class, the property, and of course i didn't remove the one inside the constructor...

        public class IDataAccesslayer
        {
        private static SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["connStr"].ToString());

        public IDataAccesslayer()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        
        public static void ExecuteNoReturn(String spName, List<SqlParameter> parms)
        {
            try
            {
                conn.Open();
        
                SqlCommand cmd = new SqlCommand(spName, conn);
                cmd.CommandType = CommandType.StoredProcedure;
        
                foreach (SqlParameter parm in parms)
                {
                    cmd.Parameters.Add(parm);
                }
        
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                if (conn.State == ConnectionState.Open)
                    conn.Close();
            }
        }
        public static DataSet ExecuteReturnDataSet(String spName, List<SqlParameter> parms)
        {
            //this was same as previous, except using a data-adapter
        }
        

        }

        J Offline
        J Offline
        Jason Vetter
        wrote on last edited by
        #3

        I also like: WebConfigurationManager.ConnectionStrings("connStr").ToString() Maybe he wasn't confident enough that WebConfigurationManager.ConnectionStrings("connStr") would return a string. Maybe he should be sure with: WebConfigurationManager.ConnectionStrings("connStr").ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString().ToString()

        1 Reply Last reply
        0
        • C ColinBashBash

          ugh. if only we all understood how static works... and perhaps naming conventions... hmm, i guess understanding when to apply the word "static" to a class might also be helpful... i don't even care about the bad use of List<SqlParameter>. Oh and don't worry, there were comments for the functions, the class, the property, and of course i didn't remove the one inside the constructor...

          public class IDataAccesslayer
          {
          private static SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["connStr"].ToString());

          public IDataAccesslayer()
          {
              //
              // TODO: Add constructor logic here
              //
          }
          
          public static void ExecuteNoReturn(String spName, List<SqlParameter> parms)
          {
              try
              {
                  conn.Open();
          
                  SqlCommand cmd = new SqlCommand(spName, conn);
                  cmd.CommandType = CommandType.StoredProcedure;
          
                  foreach (SqlParameter parm in parms)
                  {
                      cmd.Parameters.Add(parm);
                  }
          
                  cmd.ExecuteNonQuery();
              }
              catch (Exception ex)
              {
                  throw (ex);
              }
              finally
              {
                  if (conn.State == ConnectionState.Open)
                      conn.Close();
              }
          }
          public static DataSet ExecuteReturnDataSet(String spName, List<SqlParameter> parms)
          {
              //this was same as previous, except using a data-adapter
          }
          

          }

          _ Offline
          _ Offline
          _Erik_
          wrote on last edited by
          #4

          I wonder... What moves a man to type an "I" at the begining of a bad named DataAccesslayer class for naming a static class which is not static, and even has a default constructor to construct absolutely nothing?

          1 Reply Last reply
          0
          • G GibbleCH

            Don't forget the abomination that is

            throw (ex);

            P Offline
            P Offline
            peterchen
            wrote on last edited by
            #5

            Gaaah!!!

            throw new Stone();

            Agh! Reality! My Archnemesis![^]
            | FoldWithUs! | sighist | WhoIncludes - Analyzing C++ include file hierarchy

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups