Exemplo n.º 1
0
        public override IBaseItem Get(IBaseItem item)
        {
            string mySql = string.Empty;
            IBlogEntry myEntry = item as IBlogEntry;
            IList<string> myValues = new List<string>();

            if (item.Id == null)
            {
                myValues.Add(myEntry.Title);
                myValues.Add(myEntry.Subtitle);
                myValues.Add(myEntry.DateCreated.ToString());
                mySql = FillItem(GET_SQL_NO_ID, myValues);
            }
            else
            {
                myValues.Add(myEntry.Id.ToString());
                mySql = FillItem(GET_SQL_ID, myValues);
            }

            using (SqlCeConnection myConnection = DataAccess.Connection())
            {
                myConnection.Open();

                using (SqlCeCommand myCommand = myConnection.CreateCommand())
                {
                    myCommand.CommandText = mySql;

                    using (SqlCeDataReader myReader = myCommand.ExecuteReader())
                    {
                        while (myReader.Read())
                        {
                            myEntry = new BlogEntry();

                            myEntry.Id = Convert.ToInt32(myReader[FIELD_ID]);
                            myEntry.Title = myReader[FIELD_TITLE].ToString();
                            myEntry.Subtitle = myReader[FIELD_SUBTITLE].ToString();
                            myEntry.Content = myReader[FIELD_CONTENT].ToString();
                            myEntry.DateCreated = DateTime.Parse(myReader[FIELD_CREATED].ToString());
                            myEntry.CreatedBy = myReader[FIELD_CREATED_BY].ToString();
                        }
                    }

                    myConnection.Close();
                }
            }

            return myEntry;
        }
Exemplo n.º 2
0
        public override IEnumerable<IBaseItem> GetRows(IBaseItem item)
        {
            List<IBlogEntry> myEntries = new List<IBlogEntry>();

            using (SqlCeConnection myConnection = DataAccess.Connection())
            {
                myConnection.Open();

                using (SqlCeCommand myCommand = myConnection.CreateCommand())
                {
                    myCommand.CommandText = GET_ROWS_SQL;

                    using (SqlCeDataReader myReader = myCommand.ExecuteReader())
                    {
                        while (myReader.Read())
                        {
                            IBlogEntry myEntry = new BlogEntry();

                            myEntry.Id = Convert.ToInt32(myReader[FIELD_ID]);
                            myEntry.Title = myReader[FIELD_TITLE].ToString();
                            myEntry.Subtitle = myReader[FIELD_SUBTITLE].ToString();
                            myEntry.Content = myReader[FIELD_CONTENT].ToString();
                            myEntry.DateCreated = DateTime.Parse(myReader[FIELD_CREATED].ToString());
                            myEntry.CreatedBy = myReader[FIELD_CREATED_BY].ToString();

                            myEntries.Add(myEntry);
                        }
                    }

                    myConnection.Close();
                }
            }

            return myEntries;
        }