DbContextが破棄されたため、操作を完了できません。DbContextが破棄されているため、操作を完了できません。実行中のプログラムに影響する
誰かがこの問題で私を助けてくれるのだろうかと思っていました。ここに私のコードは次のとおりです。
public partial class CustomerResearchForm : MetroFramework.Forms.MetroForm
{
FactorEntities contex;
public CustomerResearchForm()
{
InitializeComponent();
}
private void CustomerResearchForm_Load(object sender, EventArgs e)
{
}
private void CResearchGrid_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{
CustomerUpdateAndDelete CustomerUpdateAndDelete = new CustomerUpdateAndDelete();
using ( contex =new FactorEntities())
{
var sendergrid=(DataGridView)sender;
int customercode = Convert.ToInt32(sendergrid.Rows[e.RowIndex].Cells[1].Value);
var customer = from _customer in contex.tblCustomers where
_customer.CustomerCode==customercode select _customer;
CustomerUpdateAndDelete.tblCustomerBindingSource.DataSource = customer.ToList();
CustomerUpdateAndDelete.Show();
CustomerUpdateAndDelete.tblCustomerBindingNavigatorSaveItem.Click+=tblCustomerBindingNavigatorSaveItem_Click;
}
}
private void tblCustomerBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
contex.SaveChanges();
throw new NotImplementedException();
}
}
例外は、この行で発生します。
contex.SaveChanges();
私は、私が何をすべき私のコンテキストにVARを使用することはできませんか?
あなたの文脈は 'using(){}'の中のオブジェクトが自動散布されるのを知っていることを知っています。 – MethodMan
キーワードでC#google検索を実行する – MethodMan
親愛なる@MethodMan私はそれを手に入れました。私は自分のコードから削除し、エラーは消えました。まだ私はcontex情報を編集した後、私のデータベースを更新しません! :( –