Ejemplo n.º 1
0
        private List <ServiceNotices> GetPlatformServiceNotices()
        {
            // Get All Special Service Notices
            string connectionString       = System.Configuration.ConfigurationManager.ConnectionStrings["NextBusDisplayConnectionString"].ConnectionString;
            string strSQL                 = "SELECT AutoID, ServiceNoticeID, DisplayFrom, DisplayTo, DisplayText FROM dbo.ServiceNotice ORDER BY DisplayFrom, DisplayTo;";
            List <ServiceNotices> results = new List <ServiceNotices>();   // http://forums.asp.net/t/1654695.aspx/1

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                SqlCommand command = new SqlCommand(strSQL, connection);
                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                if (reader.HasRows)
                {
                    // http://stackoverflow.com/a/8249371/69039     How to convert sqldatareader to list of dto's?
                    // Set Up the Read / Index The Columns
                    int AutoID          = reader.GetOrdinal("AutoID");
                    int ServiceNoticeID = reader.GetOrdinal("ServiceNoticeID");
                    int DisplayFrom     = reader.GetOrdinal("DisplayFrom");
                    int DisplayTo       = reader.GetOrdinal("DisplayTo");
                    int DisplayText     = reader.GetOrdinal("DisplayText");

                    // Call Read before accessing data.
                    while (reader.Read())
                    {
                        // Add The Results To The List
                        // http://stackoverflow.com/questions/6042404/how-to-put-values-from-datareader-into-listt
                        var nr = new ServiceNotices();
                        nr.AutoID          = reader.GetInt32(AutoID);
                        nr.ServiceNoticeID = reader.GetString(ServiceNoticeID);
                        nr.DisplayFrom     = reader.GetDateTime(DisplayFrom);
                        nr.DisplayTo       = reader.GetDateTime(DisplayTo);
                        nr.DisplayText     = reader.GetString(DisplayText);
                        results.Add(nr);
                    }
                }

                // Call Close when done reading.
                reader.Close();
            }
            // linq failure
            //List<ServiceNotices> results = (from z in dc.ServiceNotices
            //                                orderby z.DisplayFrom, z.DisplayTo
            //                                select z.[0] [1] [2] [3] [4]).ToList();
            //                                //select z.["AutoID"] ["ServiceNoticeID"] ["DisplayFrom"] ["DisplayTo"] ["DisplayText"]).ToList();
            //return results; // ToArray().ToList();
            return(results); // ToArray().ToList();
        }
Ejemplo n.º 2
0
 partial void DeleteServiceNotices(ServiceNotices instance);
Ejemplo n.º 3
0
 partial void UpdateServiceNotices(ServiceNotices instance);
Ejemplo n.º 4
0
 partial void InsertServiceNotices(ServiceNotices instance);