예제 #1
0
파일: Contacts.cs 프로젝트: Arshir/PCC
        public static Contacts[] MapFrom(DataSet ds)
        {
            List<Contacts> objects;

            // Initialise Collection.
            objects = new List<Contacts>();

            // Validation.
            if (ds == null)
                throw new ApplicationException("Cannot map to dataset null.");
            else if (ds.Tables[TABLE_NAME].Rows.Count == 0)
                return objects.ToArray();

            if (ds.Tables[TABLE_NAME] == null)
                throw new ApplicationException("Cannot find table [dbo].[contacts] in DataSet.");

            if (ds.Tables[TABLE_NAME].Rows.Count < 1)
                throw new ApplicationException("Table [dbo].[contacts] is empty.");

            // Map DataSet to Instance.
            foreach (DataRow dr in ds.Tables[TABLE_NAME].Rows)
            {
                Contacts instance = new Contacts();
                instance.MapFrom(dr);
                objects.Add(instance);
            }

            // Return collection.
            return objects.ToArray();
        }
예제 #2
0
파일: Contacts.cs 프로젝트: Arshir/PCC
        public static Contacts Get(System.Int64 no)
        {
            DataSet ds;
            Database db;
            string sqlCommand;
            DbCommand dbCommand;
            Contacts instance;

            instance = new Contacts();

            db = MyDatabase.DB;
            sqlCommand = "[dbo].Contacts_SELECT";
            dbCommand = db.GetStoredProcCommand(sqlCommand, no);

            // Get results.
            ds = db.ExecuteDataSet(dbCommand);
            // Verification.
            if (ds == null || ds.Tables[0].Rows.Count == 0) throw new ApplicationException("Could not get Contacts ID:" + no.ToString()+ " from Database.");
            // Return results.
            ds.Tables[0].TableName = TABLE_NAME;

            instance.MapFrom( ds.Tables[0].Rows[0] );
            return instance;
        }