Как исправить 'entityvalidationerrors' в C#
I tried to make the application and connect it to the SQL Server. but I have a problem with the following line of code.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; namespace CBIR { public partial class training : Form { string fileName; public training() { InitializeComponent(); } private void Pilihgbr_Click(object sender, EventArgs e) { using (OpenFileDialog dialog = new OpenFileDialog() { Filter = "JPG Files(*.jpg)|*.jpg|PNG Files(*.png)|*.png|All Files(*.*)|*.*", ValidateNames = true, Multiselect = false }) { if (dialog.ShowDialog() == DialogResult.OK) { fileName = dialog.FileName; pictureBox1.Image = Image.FromFile(fileName); } } } byte[] ConvertImage (Image img) { using (MemoryStream ms = new MemoryStream()) { img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); return ms.ToArray(); } } private async void Mulaitraining_Click(object sender, EventArgs e) { using (cbirEntities db = new cbirEntities()) { tabel_cbir pic = new tabel_cbir() { Nama_Gambar = fileName, Gambar = ConvertImage (pictureBox1.Image)}; db.tabel_cbir.Add(pic); await db.SaveChangesAsync(); MessageBox.Show("Tersimpan", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } private void balik_Click(object sender, EventArgs e) { menuutama m1 = new menuutama(); m1.Show(); this.Close(); } } }
and an error occurred while running the program on the line.
await db.SaveChangesAsync();
сообщение об ошибке "EntityValidationError", как это исправить?
Any help will be appreciated. Thanks.
Что я уже пробовал:
Я попытался использовать try-catch, чтобы исправить это, но это все еще не работает.