コード例 #1
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            using (PicEntities db = new PicEntities())
            {
                var pic = new MyPicture()
                {
                    FileName = _fileName, Data = ConvertImageToBinary(pictureBox.Image)
                };
                db.MyPictures.Add(pic);
                try
                {
                    await db.SaveChangesAsync();

                    MessageBox.Show(@"You have been successfully saved.", @"Message", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            System.Console.WriteLine(@"Property: {0} Error: {1}", validationError.PropertyName, validationError.ErrorMessage);
                        }
                    }
                }
            }
        }
コード例 #2
0
 private void btnLoad_Click(object sender, EventArgs e)
 {
     listView.Items.Clear();
     using (PicEntities db = new PicEntities())
     {
         _list = db.MyPictures.ToList();
         foreach (var pic in _list)
         {
             ListViewItem item = new ListViewItem(pic.FileName);
             listView.Items.Add(item);
         }
     }
 }
コード例 #3
0
        private async void btnSave_Click(object sender, EventArgs e)
        {
            using (PicEntities db = new PicEntities())
            {
                MyPucture pic = new MyPucture()
                {
                    FileName = filename, Data = ConvertImageToBinary(pictureBox.Image)
                };
                db.MyPuctures.Add(pic);
                await db.SaveChangesAsync();

                MessageBox.Show("You have been Successfuly Saved.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }