473,395 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

mysql in operator

99
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 1118
kenobewan
4,871 Expert 4TB
Have you tried:
Expand|Select|Wrap|Line Numbers
  1. "select name from users where id in ('" + ids + "')"
Feb 9 '07 #2
xwero
99
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
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 Expert 4TB
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
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...
5
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...
0
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...
4
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...
57
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
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 =...
2
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...
12
by: howa | last post by:
any side effect for PHP? what do you think?
7
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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...

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.