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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:39:08+00:00 2026-06-02T15:39:08+00:00

Table: id userid friendid name status 1 1 2 venkat false 2 1 3

  • 0

Table:

id     userid  friendid   name    status
1      1        2         venkat  false
2      1        3         sai     true
3      1        4         arun    false
4      1        5         arjun   false

If a user sends userid=1,friendids=2,4,5 status=true

How would I write the query to update the above? All friendids status is true. [2,3,4 at a time]?

  • 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-02T15:39:10+00:00Added an answer on June 2, 2026 at 3:39 pm

    To update one column here are some syntax options:

    Option 1

    var ls=new int[]{2,3,4};
    using (var db=new SomeDatabaseContext())
    {
        var some= db.SomeTable.Where(x=>ls.Contains(x.friendid)).ToList();
        some.ForEach(a=>a.status=true);
        db.SubmitChanges();
    }
    

    Option 2

    using (var db=new SomeDatabaseContext())
    {
         db.SomeTable
           .Where(x=>ls.Contains(x.friendid))
           .ToList()
           .ForEach(a=>a.status=true);
    
         db.SubmitChanges();
    }
    

    Option 3

    using (var db=new SomeDatabaseContext())
    {
        foreach (var some in db.SomeTable.Where(x=>ls.Contains(x.friendid)).ToList())
        {
            some.status=true;
        }
        db.SubmitChanges();
    }
    

    Update

    As requested in the comment it might make sense to show how to update multiple columns. So let’s say for the purpose of this exercise that we want not just to update the status at ones. We want to update name and status where the friendid is matching. Here are some syntax options for that:

    Option 1

    var ls=new int[]{2,3,4};
    var name="Foo";
    using (var db=new SomeDatabaseContext())
    {
        var some= db.SomeTable.Where(x=>ls.Contains(x.friendid)).ToList();
        some.ForEach(a=>
                        {
                            a.status=true;
                            a.name=name;
                        }
                    );
        db.SubmitChanges();
    }
    

    Option 2

    using (var db=new SomeDatabaseContext())
    {
        db.SomeTable
            .Where(x=>ls.Contains(x.friendid))
            .ToList()
            .ForEach(a=>
                        {
                            a.status=true;
                            a.name=name;
                        }
                    );
        db.SubmitChanges();
    }
    

    Option 3

    using (var db=new SomeDatabaseContext())
    {
        foreach (var some in db.SomeTable.Where(x=>ls.Contains(x.friendid)).ToList())
        {
            some.status=true;
            some.name=name;
        }
        db.SubmitChanges();
    }
    

    Update 2

    In the answer I was using LINQ to SQL and in that case to commit to the database the usage is:

    db.SubmitChanges();
    

    But for Entity Framework to commit the changes it is:

    db.SaveChanges()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Users table user_id pic_url name friends table auto_id userid friendid status actions table auto_id
why select 'aaa' =0 return 1 (TRUE) if i have a table like userid
I have this sql statement: CREATE TABLE [dbo].[User]( [UserId] [int] IDENTITY(1,1) NOT NULL, [FirstName]
I have a table that stores user information. The table has a userid (identity)
I have a table users with primary index userId . Currently, each user has
I have a table which links the userID and the friendID (which is another
I have a table like the following table: UserID Num1 Num2 Code Name Cat
//user: id name password how to properly make friends system? how should look table
Many people say that I should create a friendships table( userid , friendid ).
Consider this as my json string, {Table : [{userid : 11,name : KumarP,designation :

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.