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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T01:35:47+00:00 2026-05-20T01:35:47+00:00

I have to upgrade the following code to use prepared statements: OdbcCommand cmd =

  • 0

I have to upgrade the following code to use prepared statements:

OdbcCommand cmd = sql.CreateCommand();
cmd.CommandText = "SELECT [EMail] from myTable WHERE "+,
for (int i = 0; i < 50; i++)
{
   if (i > 0)
   {
      cmd.CommandText += " OR ";
   }
   cmd.CommandText += "UNIQUE_ID = " + lUniqueIDS[i];
}

Forbid my stupid code above, it’s just an example… I’m trying to fetch all the Emails of users with IDs either x, y, z, etc…

The question is – how can I rewrite it using prepared statements?
A blind naive guess would be

for (int i = 0; i < 50; i++)
{
   if (i > 0)
   {
      cmd.CommandText += " OR ";
   }
   cmd.CommandText += "UNIQUE_ID = ?";
   cmd.Parameters.Add("@UNIQUE_ID", OdbcType.BigInt).Value = lUniqueIDS[i];
}

Should it work? Can I append the same parameter (unique_id) more than once?

  • 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-05-20T01:35:48+00:00Added an answer on May 20, 2026 at 1:35 am

    It looks like you’re using positional parameters (i.e. ? in the query, rather than @UNIQUE_ID) which means the names of the parameters shouldn’t matter as far as the SQL is concerned. However, I wouldn’t be entirely surprised to see the provider complain… and it may make diagnostics harder too. I suggest you use the index as a suffix:

    cmd.Parameters.Add("@UNIQUE_ID" + i, ObdcType.BigInt).Value = lUniqueIDs[i];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following on from my last question : I've written some code to upgrade a
I have the following bit of code that worked as expected before we upgraded
I've been useing VS2005 to create sql reports and now have to upgrade to
i have a windows client and i want to upgrade subversion from 1.5.3 to
I have the following code in a header included in main.mm: 1. virtual int
In my forum I have a BB code to display youtube videos. following options
i'm trying to upgrade an old CMS to use NHibernate and can't deter from
I have the following code private void LoadIntoMemory() { //Init large HashSet HashSet<document> hsAllDocuments
We are trying to upgrade our code base to use Visual Studio 2010 but
I have the following post button that i use for paypal transactions: <form action=https://www.sandbox.paypal.com/cgi-bin/webscr

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.