Использую Devart Linq to SQLite
Есть вот такой код на добавление данных
| Код | private void TS_Meal_Add_Click(object sender, EventArgs e) { int perid = All.StrToInt(LB_Diet.SelectedValue.ToString()); MContext.MDataContext mc = new MContext.MDataContext(); MContext.Meal me = new MContext.Meal();
if (AE_Meal.Show("Добавить", perid,out me)) { mc.Meals.InsertOnSubmit(me); mc.SubmitChanges(); Select_Diet_Child(perid); } }
|
Он работает все хорошо.. А вот на изменение не хочет...
| Код | private void TS_Meal_Edit_Click(object sender, EventArgs e) { int row = this.DGV_Meals.SelectedRows[0].Index; int col = this.DGV_Meals.Columns["ID"].Index; int id = All.StrToInt(this.DGV_Meals[col, row].Value.ToString());
MContext.MDataContext mc = new MContext.MDataContext(); MContext.Meal me = (from k in mc.Meals where k.IdMeals == id select k).Single();
while (AE_Meal.Show("###", me, out me)) { int count = (from k in mc.Meals where (k.NameMeals == me.NameMeals) && (k.MealsTime == me.MealsTime) && (k.Percent == me.Percent) select k).Count(); if (count < 2) { mc.SubmitChanges(); Select_Diet_Child(All.StrToInt(me.IdDiet.ToString())); return; } else MessageBox.Show("###.", "###", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
|
Класс AE_Meal
| Код | public partial class AE_Meal : Form { public AE_Meal() { InitializeComponent(); }
bool t = false; MContext.Meal meal = new MContext.Meal();
public static bool Show(String Name, int parent, out MContext.Meal out_me) { return Show(Name, new MContext.Meal{IdDiet = parent, NameMeals ="", Percent=0, MealsTime = DateTime.Now }, out out_me); } public static bool Show(String Name, MContext.Meal me, out MContext.Meal out_me) { AE_Meal AEMeal = new AE_Meal(); AEMeal.Text = Name; AEMeal.mName.Text = me.NameMeals.ToString(); AEMeal.MTime.Value = me.MealsTime.Value; AEMeal.MPercent.Text = me.Percent.ToString(); AEMeal.meal.IdDiet = me.IdDiet; AEMeal.meal.IdMeals = me.IdMeals; AEMeal.ShowDialog();
out_me = AEMeal.meal;
return AEMeal.t; }
private void ok_Click(object sender, EventArgs e) { if ((mName.TextLength == 0) || (MPercent.TextLength == 0)) { MessageBox.Show("Заполните все поля", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } else { this.meal.NameMeals = mName.Text.ToString(); this.meal.MealsTime = MTime.Value; this.meal.Percent = All.StrToInt(MPercent.Text.ToString()); } this.t = true; this.Close(); } private void cancel_Click(object sender, EventArgs e) { this.Close(); } private void MPercent_KeyPress(object sender, KeyPressEventArgs e) { e.Handled = true;
int len = (sender as TextBox).TextLength;
if (Char.IsDigit(e.KeyChar) && (len < 2)) e.Handled = false; } }
|
Делал трассировку, в контексте данные обновляются, но в БД нет... |