コード例 #1
0
ファイル: DB.cs プロジェクト: Shamil-R/dentsu_aegis
 public int Insert(List<Item> list)
 {
     LocalDBEntities db = new LocalDBEntities();
     try
     {
         foreach (Item item in list)
         {
             test record = (from r in db.test.Where
                                  (a => a.date == item.date)
                                      select r).FirstOrDefault();
             if (record == null)
             {
                 db.test.Add(new test
                 {
                     date = item.date,
                     views = item.views,
                     clicks = item.clicks
                 });
             }
         }
         db.SaveChanges();
     }
     catch (Exception e)
     {
         return -1;
     }
     return 0;
 }
コード例 #2
0
ファイル: DB.cs プロジェクト: Shamil-R/dentsu_aegis
        public int out_DB_in_file()
        {
            LocalDBEntities db = new LocalDBEntities();

            try
            {
                var result = from r in db.test select r;
                string lines = "Date       Views  Clicks\n";
                foreach (var r in result)
                {
                    lines += r.date + " " + Convert.ToString(r.views) + " " + Convert.ToString(r.clicks) + "\n";
                }
                System.IO.File.WriteAllText(@"C:\Users\Rafa\Desktop\test-dan\test\WriteLines.txt", lines);
            }
            catch (Exception e)
            {
                return -1;
            }
            return 0;
        }