/** *\brief A function get the magazine list *\return The magazine list */ public static List <Magazine> GetMagazineList() { SqlCommand sqlSelectCommand = Magazine.GetSelectCommand(); List <Magazine> MagazineList = new List <Magazine>(); try { DatabaseHandler.SQL_CONNECTION.Open(); SqlDataReader reader = sqlSelectCommand.ExecuteReader(); while (reader.HasRows && reader.Read()) { object[] attributesOfMagazine = new object[5]; // Magazine class has 5 attributes. reader.GetValues(attributesOfMagazine); // Get the first row. Magazine newMagazine = new Magazine(0, "a", 0); newMagazine.Fill(attributesOfMagazine); MagazineList.Add(newMagazine); } DatabaseHandler.SQL_CONNECTION.Close(); return(MagazineList); } catch (Exception error) { MessageBox.Show(error.Message); return(null); } }
/* DATA ADAPTER && DATA SET */ /** *\brief A function to get the SQL data adapter for the given table name *\param sourceTableName: Name of the source table *\return The SQL data adapter */ public static SqlDataAdapter GetDataAdapterFor(string sourceTableName) { if (sourceTableName == "tblCustomer") { return(new SqlDataAdapter(Customer.GetSelectCommand().CommandText, DatabaseHandler.CONNECTION_STRING)); } if (sourceTableName == "tblBook") { return(new SqlDataAdapter(Book.GetSelectCommand().CommandText, DatabaseHandler.CONNECTION_STRING)); } if (sourceTableName == "tblMagazine") { return(new SqlDataAdapter(Magazine.GetSelectCommand().CommandText, DatabaseHandler.CONNECTION_STRING)); } if (sourceTableName == "tblMusicCD") { return(new SqlDataAdapter(MusicCD.GetSelectCommand().CommandText, DatabaseHandler.CONNECTION_STRING)); } return(null); }