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

I am in the process of converting a static website into one using a
What is the process of converting win32 application (a small popup window actually) to
Im in the process of converting my rails code which developed in version 2
I'm in the process of converting some LaTeX documentation to restructured text and having
I am in process of converting Visual Basic app into Python Django. Currently, it
I am in the process of converting thousands of lines of batch code into
I'm in the process of converting parts of an application to use ASP.NET MVC
I am in the process of converting several websites from a raw PHP templating
We are in the process of converting a Swing application to SWT and it's
I'm in the process of converting a Paradox database application written in Delphi to

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.