Example #1
0
        private List <Suggestion> GetAllSuggestions()
        {
            List <Suggestion> suggestions = new List <Suggestion>();

            SqlConnection sqlconn    = commonContext.connectonToMSSQL();
            string        sqlCommand = string.Format(@"use {0}; select  * from QT_Suggestion order by PublishTime;", DBName);

            sqlconn.Open();
            SqlCommand cmd = new SqlCommand(sqlCommand, sqlconn);

            SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            while (reader.Read())
            {
                Suggestion suggestion = new Suggestion();
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    PropertyInfo property = suggestion.GetType().GetProperty(reader.GetName(i));
                    property.SetValue(suggestion, reader.IsDBNull(i) ? "[null]" : reader.GetValue(i), null);
                }
                suggestions.Add(suggestion);
            }
            reader.Close();
            return(suggestions);
        }