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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:16:27+00:00 2026-06-12T20:16:27+00:00

I have a table named industries . In this my fields are workfor_id ,

  • 0

I have a table named industries. In this my fields are

  • workfor_id,
  • workfor_usr_id,
  • workfor_industry_id.

With the same values of workfor_id, I have different workfor_industry_id‘s.

foreach (var k in us){ 
    var ind = dbContext.industries.Where(i => i.workfor_id == 
        k.id).Select(i => i).FirstOrDefault(); 
    string ind2 = k.industry; 
    var industryParts =   ind2.Split(','); 
    var o = (industryParts.Length); 
    for (c = 0; c < o; c++){  
    ind.workfor_id = Convert.ToInt16(k.id); 
    ind.workfor_industry_id = Convert.ToInt16(k.industryid); }
     }

To update workfor_industry_id field I have implemented inner loop inside the foreach loop to get the values of workfor_industry_id’s.here same record is over loading with different workfor_industry_id’s.

can you tell me how to implement 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-06-12T20:16:29+00:00Added an answer on June 12, 2026 at 8:16 pm

    UPDATED
    This update adds a little more error checking and assumes that -1 is never a valid value for industry_id

    short GetShort(string value) {
      short returnValue;
      value = (value ?? string.Empty).Replace("\"",null);
      return short.TryParse(value, out returnValue) ? returnValue : (short)-1;
    }
    
    foreach (var k in us){ 
      var id=Convert.ToInt16(k.id);
      var toRemove=from i in dbContext.industries
                   where i.workfor_id == k.id
                   select i;
      var toAdd = from x in (k.industry ?? string.Empty).Split(',')
                  select new Industry { 
                          workfor_id=id,
                          workfor_industry_id=GetShort(x)
                        };
    
      dbContext.industries.DeleteAllOnSubmit(toRemove); 
      dbContext.industries.InsertAllOnSubmit(toAdd.Where(x=>x.workfor_industry_id != -1));
    
    }
    dbContext.SubmitChanges();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have table named Schedule which has fields named TeacherName and ClassTakenDate.The values in
I have this table named sample with these values in MS Sql Server: ID
I have one table named Staff in access and also have this table(same name)
I have a table named datas and I'm executing a query like this: SELECT
I have a table named size here, something like this: size id | size
I have table named highscore like this: nameQL scoreQL piotr 50 And flash game
i have one table named category. in this table i have two columns 1.)
I have a table named PARAMETER looking like this: ID - number NAME -
I have a table named product_table as below with two fields product_id and comp_prod
i have a table named customer_age that loks like this: ID 1 2 3

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.