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

  • Home
  • SEARCH
  • 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 8744883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:54:52+00:00 2026-06-13T11:54:52+00:00

Code: string sqlCommand = @UPDATE table SET active = 0 WHERE id IN (@CommaSeparatedId);

  • 0

Code:

string sqlCommand = @"UPDATE table SET active = 0 WHERE id IN (@CommaSeparatedId)";
string sqlParamName = "CommaSeparatedId";
string sqlParamValue = "111, 222";

try
{
    using (NpgsqlConnection connection = new NpgsqlConnection())
    {
        // Get connection string from Web.config
        connection.ConnectionString = _connectionString;
        connection.Open();
        Int32 rowsAffected;

        using (NpgsqlCommand command = new NpgsqlCommand(sqlCommand, connection))
        {
            NpgsqlParameter sqlParam = new NpgsqlParameter(sqlParamName, NpgsqlTypes.NpgsqlDbType.Varchar);
            // Code below no exception occur, and active not updated to 0
            // sqlParam.Value = sqlParamValue;

            // This code works for only one value
            sqlParam.Value = "111";

            command.Parameters.Add(sqlParam);
            rowsAffected = command.ExecuteNonQuery();
        }
    }
}
catch (NpgsqlException pgEx)
{
    throw pgEx;
}

The problem is:

If I’m using the 111, 222 as the sqlParam.Value'rowsAffected = 0, but if I'm using only111or222rowsAffected = 1`. That means it success to updated when only 1 value but will failed if trying to update more than 1 value.


Expected Query:

UPDATE table
    SET active = 0
WHERE id IN ('111', '222');

What I’m missing in code above?

  • 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-13T11:54:53+00:00Added an answer on June 13, 2026 at 11:54 am

    The problem you are facing is due to the fact that the parameter value “111,222” will be seen by the database engine not like two distinct values, but as one.
    The database search for a record with ID = “111,222” and find nothing matching the request.
    You should try to use a stored procedure and execute a Dynamic SQL according to the syntax required by PostgreSQL

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

Sidebar

Related Questions

Replaces Question: Update multiple rows into SQL table Here's a Code Snippet to update
I have this code UPDATE OPENQUERY (db,'SELECT * FROM table WHERE ref = ''+
Code: String message = MessageFormat.format(error {0},e); E.g. message: java.text.ParseException: Unparseable date: sdf sf sa
The code String s = y z a a a b c c z;
I've got the code: string key = , value = , type = ;
I have the following code: String website = http://www.somewebsite.com/; Document doc = Jsoup.connect(website).get(); Elements
Given the following code: string source = Some Unicode String; foreach( char value in
Here's the code: string name = myName; int id = (int)_myDB.ThingTable.Where(thing => thing.ThingName ==
I have the following code string three() { return three; } void mutate(string& ref)
I have the following code: string acctStatus = account.AccountStatus.ToString(); if (!SettableStatuses().Any(status => status ==

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.