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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:48:46+00:00 2026-05-11T09:48:46+00:00

I am in the process of converting several queries which were hard-coded into the

  • 0

I am in the process of converting several queries which were hard-coded into the application and built on the fly to parameterized queries. I’m having trouble with one particular query, which has an in clause:

UPDATE TABLE_1 SET STATUS = 4 WHERE ID IN (1, 14, 145, 43); 

The first parameter is easy, as it’s just a normal parameter:

MySqlCommand m = new MySqlCommand('UPDATE TABLE_1 SET STATUS = ? WHERE ID IN (?);'); m.Parameters.Add(new MySqlParameter('', 2)); 

However, the second parameter is a list of integers representing the ids of the rows that need updating. How do I pass in a list of integers for a single parameter? Alternatively, how would you go about setting up this query so that you don’t have to completely build it each and every time you call it, and can prevent SQL injection attacks?

  • 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. 2026-05-11T09:48:47+00:00Added an answer on May 11, 2026 at 9:48 am

    You could build up the parametrised query ‘on the fly’ based on the (presumably) variable number of parameters, and iterate over that to pass them in.

    So, something like:

    List foo; // assuming you have a List of items, in reality, it may be a List<int> or a List<myObject> with an id property, etc.  StringBuilder query = new StringBuilder( 'UPDATE TABLE_1 SET STATUS = ? WHERE ID IN ( ?') for( int i = 1; i++; i < foo.Count ) {   // Bit naive      query.Append( ', ?' ); }  query.Append( ' );' );  MySqlCommand m = new MySqlCommand(query.ToString()); for( int i = 1; i++; i < foo.Count ) {     m.Parameters.Add(new MySqlParameter(...)); } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Our shop is in the process of converting our internal project management application from
Has anybody gone through the process of converting a real-world business application from ASP.NET
I'm in the process of converting a varchar(8000) field to an xml field in
I was in the process of converting a VS2003 project (.NET 1.1) to VS2008
I am in the process of converting a VS 2008 Web Site to a
I'm in the process of refactoring some code which includes moving folders around, and
We're in the process of converting web app to IE8 (now client is using
Java process control is notoriously bad - primarily due to inadequate support by the
There is a conversion process that is needed when migrating Visual Studio 2005 web
A Windows process created from an exe file has access to the command string

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.