Page 1 of 1

Parameter Array

Posted: Thu 21 Feb 2008 06:40
by sportsoft
Hi All

I have the following data adapter selectcommand:

SELECT * FROM game_type WHERE game_type_id IN (@game_type_list) AND (deleted=0) ORDER BY game_type_name asc

I want to pass an array to this list with comma separated values ie

Code: Select all

MySqlDataAdapter_game_type.SelectCommand.Parameters.Add("@game_type_list", CoreLab.MySql.MySqlType.BigInt, 20).Value = "1,2,3"
Obviously, this does not work as its passing a string to a int type, but I cant use varchar type either as this is an int type column in the table.

The SQL query that I am trying to replicate would look like this:

SELECT * FROM game_type WHERE game_type_id IN (1,2,3) AND (deleted=0) ORDER BY game_type_name asc

How can I do this with a parameter?

Nick

Posted: Thu 21 Feb 2008 12:19
by Alexey.mdr
It does not matter what types you are passing.
Because it's a SELECT statement, it is being passed to the server as string type.
Will this block of code make it work?

Code: Select all

---
SELECT * FROM game_type WHERE game_type_id IN (@game_type_list) AND (deleted=0) ORDER BY game_type_name asc;
--- 
    
string arrVal = "1,2,3";
MySqlDataAdapter_game_type.SelectCommand.Parameters.Add("game_type_list", arrVal);