473,809 Members | 2,757 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mysql in operator

99 New Member
Hello i looked in many fora and on many documentation websites but i can't find a way to use the in operator in a mysql query without having an error.

Expand|Select|Wrap|Line Numbers
  1. select name from users where id in (?)
When i parameterize the query like that i get an error saying i don't use the right odbctype. i use int but of course most of the time it's a comma seperated string. If i use the string odbctype i get the same error.

Expand|Select|Wrap|Line Numbers
  1. "select name from users where id in ("+ ids+")"
I get what i want but there are occasions where i want to work with those query values, for instance use them in another query, but i can't the only thing i can do is to output them.

i could do a loop of the ids but i want to keep the number of queries as low as possible.

Any light on this problem is very welcome.
Feb 8 '07 #1
4 1131
kenobewan
4,871 Recognized Expert Specialist
Have you tried:
Expand|Select|Wrap|Line Numbers
  1. "select name from users where id in ('" + ids + "')"
Feb 9 '07 #2
xwero
99 New Member
It worked, it's odd because normally you don't need to add a quotation mark inside the round brackets.


Anyway thank you.
Feb 9 '07 #3
xwero
99 New Member
Ok back to start. It only gets me the first value.

Expand|Select|Wrap|Line Numbers
  1. string mysql = "select name from users where id in ('" + ids + "')";
  2. OdbcCommand com = new OdbcCommand(mysql,conn);
  3. conn.Open();
  4. OdbcDataReader read = com.ExecuteReader();
  5. string names = "";
  6. while(read.Read())
  7. {
  8.     names += read.GetString(0)+"<br>";
  9. }
  10. read.Close();
  11. conn.Close();
  12.  
The names string only holds one name even if the ids string is like 1,2,3
Feb 9 '07 #4
kenobewan
4,871 Recognized Expert Specialist
Try:
Expand|Select|Wrap|Line Numbers
  1. while(read.Read())
  2. {
  3.     names = read.GetString(0);
  4. }
and if that doesn't work just write out read.GetString( 0)...

Hope that this helps.
Feb 9 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1779
by: cocoalearner | last post by:
I am serving a website using apache. All the php and mysql code I have written works, except for one thing. When I try to create a database named M#2 using the following call, no database is created. $db = 'M#2'; $query = "create database '$db'"; $result = @mysql_query($query); I am able to create a database just fine using this technique when it is named other things (such as M$B, or Global1). I am able to create
5
4016
by: red85 | last post by:
hello i have mysql 4.1 with win2000 SP3, i know that it is only an alpha and i don't know if someone else has already posted this problem: when i execute this sql UPDATE tableX SET fieldX=valueX WHERE id IN (SELECT tX.id FROM tableX AS tX WHERE tX.fieldY=valueY AND filedZ=valueZ);
0
1804
by: ALIEN | last post by:
Hi there I downloaded the file MySQL-4.1.0-0.src.rpm. I try to build it by entering: rpm --rebuild MySQL-4.1.0-0.src.rpm --target=i686 (i have an AthlonXP so the optimised code should work better). The problem is that compilation (and hence installation) fails with the messages: " gcc -O3 -DDBUG_OFF -O2 -march=i486 -mcpu=i686 -rdynamic -o isamchk isamchk.o
4
9718
by: Ross Contino | last post by:
Hello to all: I have been searching the web for examples on how to determine a median value in a mySQL table. I have reviewed the article at http://mysql.progen.com.tr/doc/en/Group_by_functions.html. I am an experienced VB programmer that has recently moved to PHP/mySQL. My employer has a text file outputted from a vendor specific software with data. However it cannot be manipulated because it is text. I created a web that reads the...
57
25534
by: Bing Wu | last post by:
Hi all, I am running a database containing large datasets: frames: 20 thousand rows, coordinates: 170 million row. The database has been implemented with: IBM DB2 v8.1
0
3783
by: Luca | last post by:
Hello to all, I have a problem during connection to mysql through oledb provider. I use Microsoft Visual C++ with MFC on Windows and I try to connect to mysql with the following call: hResult = CDataSource::OpenFromInitializationString (connectionString) where connectionString: Provider=MySqlProv.3.0;Data Source=prova;Integrated Security="";Password="";User= root;Location=localhost;Extended
2
1974
by: David T. Ashley | last post by:
I have a box where I'm forced to use PHP before 64-bit integers became standard ... If I run a MySQL query where one of the fields returned is 64-bit integer, how do I get this into PHP as a string? My recollection is that in the result sets it "auto types" so that it is an integer, and 64-bit integers will cause problems if one tries to assign into 32 bits. P.S.--Once into PHP as a string, I would use the bcmath library to...
12
1826
by: howa | last post by:
any side effect for PHP? what do you think?
7
9967
by: srinivembu | last post by:
Hi, I am trying to port my application from SQLite to MySQL database. I believe MySQL by default searches string in case insensitive manner while using '=' and 'like' operators in SELECT statement. I have changed the default collation of the MySQL server to ''latin1_general_cs" from "latin1_swedish_ci". After doing this, the string search is case sensitive for both '=' and 'like' operators. But I would like to search string by case...
1
9598
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of things (stored procedures, functions).. we have to manually edit. That time, we face some interesting challenges.. I failed to document all of them, but whatever I can share with u.. I will try.. :) ...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10635
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10378
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10115
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
4332
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3013
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.