상세 컨텐츠

본문 제목

Singleton Design Petturn 의 사용

C#

by happynuri 2007. 8. 10. 09:50

본문

public class FineUtil
    {
       public static string CONSTR = @"Data Source=.\SQLEXPRESS;
AttachDbFilename=|DataDirectory|\Student.mdf;
Integrated Security=True;User Instance=True";

       public static string GETALLSTUDENT = "SELECT * FROM STUDENT ";
    }

 public class FineDao
    {
        private FineSingle fines; //멤버로 선언
        public FineDao(FineSingle fines)
        {
            this.fines = fines; //멤버를 초기화
        }

   public DataSet GetAllStudent()
     {
            //dataset을 얻어내는 부분
            DataSet ds = new DataSet();
            SqlConnection conn = null;
            SqlDataAdapter adapter = null;

            try
            {
                conn = fines.GetConnection(); //커넥션이 생겼다면 유효처리
                //--
                adapter = new SqlDataAdapter(FineUtil.GETALLSTUDENT,conn);
                adapter.Fill(ds, ""); //이름을 말해야 쓸수 있도록

            }
            catch (Exception ee)
            {
                throw new Exception("GetAllStudent에서 " + ee.Message + "때문에 실행");
            }

            finally {
                if (conn != null)
                {
                    if(conn.State == ConnectionState.Open)
                    {
                        conn.Close();
                    }
                }
            }
            return  ds;

        }

    }

관련글 더보기

댓글 영역