0

I wrote the following code, according to this post: CRUD Operations using stored procedure in Entity Framework

using (var context = new SamenEntities())
{
    try
    {
        register pazhoheshgar = new register()
        {
            id = textBox1.Text.Trim(),
            name = textBox2.Text.Trim(),
            family = textBox3.Text.Trim(),
            birth_date = dateTimePicker1.Value,
            mobile = textBox8.Text.Trim(),
            email = textBox11.Text.Trim()
        };
        pazhoheshgar.id= textBox1.Text.Trim();
        context.SaveChanges();

        MessageBox.Show("OK!!!", "Done");
    }
    catch
    {
        MessageBox.Show("ERROR!!!", "error");
    }
}

I already used insert and delete stored procedure, without problem, but now the "DONE!!!" message is displayed, but the change does not occur in the database.

1
  • Firstly there is no stored procedure here, secondly your not updating anything you are adding/inserting, thirdly even for an add/insert you forgot to add it to the dbset Commented Sep 8, 2018 at 13:56

1 Answer 1

2

You have to add the new object to the dbset. If it's called registers then the code would be as follows.

context.registers.Add(pazhoheshgar);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.