Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6341571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:03:49+00:00 2026-05-24T20:03:49+00:00

I have a form with add, edit, and save buttons. The form also has

  • 0

I have a form with add, edit, and save buttons. The form also has a datagridview.

I have done this to update existing product entities and to add new product entities, then display the altered data in the datagridview.

When I click on edit button, the save button will be displayed and the statements that I have written in save button is executed.

New product entities add just fine.

My problem is that when I click on the edit button, anew row is added to datagridview instead of updating the same row.

Is there any way to check the condition whether the available product in table is updating or adding a new product before adding to table in entity framework?

    private void btnSave_Click(object sender, EventArgs e)
    {

        pictureBox1.Enabled = true;
        pictureBox1.Visible = true;
        Image image = pictureBox1.Image;
        byte[] bit = null;

        bit = imageToByteArray(image);
        product1 pd = new product1();

        string category = tbCategoryName.Text;
        string categorydesc = tbCategoryDescription.Text;

        var c = new category { category_Name = category, category_Description = categorydesc };

        pd.product_Name = tbProductName.Text;
        decimal price = Convert.ToDecimal(tbProductPrice.Text);
        pd.product_Price = price;
        pd.product_Description = tbProductdescription.Text;           
        pd.product_Image = bit;

        pd.category = c;


        tsgentity.SaveChanges();
        EquipmentFinder equipment = new EquipmentFinder();            
        equipment.productgridview.Refresh();           
        this.Close();
        equipment.ShowDialog(this);           

   }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:03:51+00:00Added an answer on May 24, 2026 at 8:03 pm

    This is just an example. What your need to do is pull the current object from collection you are editing/saving using linq and then make the changed on the retrieved object and then update i.e.

    public bool UpdateCustomer(Customer customer){   
        Customer cust = entities.Customers.FirstOrDefault(c => c.ID == customer.ID);  
        cust.Forname = customer.Forename;   
        cust.Surname = customer.Surname   
        entities.SaveChanges(); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iam new to jquery. I have a rails form. where iam going to add/edit
I have form, where some fields are looks like rows, so I can add/delete
I have a form which users can add controls to and when they right
I have a form in witch users can add their working hours view them
I have a form where users can add input fields with jQuery. <input type="text"
I have a form and I want to add a select location option. How
I have a form a user can enter their name, then it will add
Hoi! I have a form I wish to submit, but I need to add
I have a bound form in microsoft access that allows a user to add
How do you add Search form to your Views in Drupal? Do I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.