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 6358381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:21:48+00:00 2026-05-24T23:21:48+00:00

I am just got madness for getting this for updating the table related with

  • 0

I am just got madness for getting this for updating the table related with category table and product table …but i dint success in doing that …

I have these tables

               product product_id
                       product_name 
                       product_description
                       product_price
                       product_image


              category  category_id
                        catgory_name
                        category_desc

I have done like this for updating table ….using entity framework …

    private void btnSave_Click(object sender, EventArgs e)
    {

        if (lblHiddenmode.Text == "Edit")
        {
            using (var dbcontext = new TsgEntities())
            {
                pictureBox1.Enabled = true;
                pictureBox1.Visible = true;
                Image image = pictureBox1.Image;
                byte[] bit = null;

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

                string category = cbcategorytypes.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;                    
                dbcontext.SaveChanges();                 
                this.Close();
            }
        }

  }

NOTE: I am updating the product name which one has the product_id is 4 and category_id = 4

but it will shows at this statement pd.category = c; i got product_id = “0” and category_id = “0”

am i doing wrong when updating the table with category table .. is there any problem with update statement

  • 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-24T23:21:50+00:00Added an answer on May 24, 2026 at 11:21 pm

    Your code above will produce insert, not an update. In order to perform an update, you first need to retrieve a product1 instance from your context.

    I don’t know what your context looks like, so I can’t post the exact code, but it will be something like this:

    product1 pd = dbcontext.protucts.Where(p => p.productid == 4 
                                             && p.categoryid == 4).First();
    

    You can then make your changes and call dbcontext.SaveChanges() and it should update your record.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just got this error and I thought I'd share it so that someone
i just got a call from Hosting company, they claimed that my application creates
I just got pagination to work on my site, but I wanted to use
I just got a job offer to be a FE Developer, but I've never
I just got this question on an interview and had no idea how to
Just got a quick question, this is a simple thing to do via PHP
I just got the access token with publish_stream , but when i access below
just got my views to change with AJAX, but now I'm stumped on how
just got a slight problem here with updating a MySql DataGridView from visual studio
I just got an old pentium 4 and I thought, that it would be

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.