ASP.NET Simple ADO class (1)

public class PageManager{    public static PageItem GetPageByFriendlyUrl(string friendlyUrl)    {        PageItem page = null;        using (var cmd = new SqlCommand())        {            cmd.Connection = new SqlConnection("Server=(local);Database=MyWebsite;Trusted_Connection=True;");            cmd.CommandText = "select * from Page where FriendlyUrl = @FriendlyUrl";            cmd.Parameters.Add("@FriendlyUrl", System.Data.SqlDbType.NVarChar).Value = friendlyUrl;                            cmd.Connection.Open();            using (var reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))            {                if (reader.Read())                {                    page = new PageItem();                    page.PageId = (int) reader["PageId"];                    page.Title = (string) reader["Title"];                    page.ControllerName = (string) reader["ControllerName"];                    page.FriendlyUrl = (string) reader["FriendlyUrl"];                }            }            return page;        }    }    public class PageItem    {        public int Id { get; set; }        public string Title { get; set; }        public string Content { get; set; }        public string FriendlyUrl { get; set; }        public string ControllerName { get; set; }    }}

Leave a Reply

Your email address will not be published. Required fields are marked *