Click here to Skip to main content
14,984,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Is there a way to pass null values in the IN statement, like this.
SQL
select * from Table where Table.id IN (,1,2,,,)

The values in the IN statment comes when i click some checkbox in forms.
Posted
Updated 6-Jun-12 18:30pm
v3

SQL
select * 
from 
Table 
where Table.id is null
or Table.id IN (1,2)
   
Comments
VJ Reddy 8-Jun-12 4:25am
   
Good answer. 5!
try like this

C#
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
  {
      SqlDataAdapter da = new SqlDataAdapter("select * from student where stid in('',1,2)", con);
      DataSet ds = new DataSet();
      da.Fill(ds);

      GridView1.DataSource = ds;
      GridView1.DataBind();
  }
   
Comments
Arjun Menon U.K 7-Jun-12 0:30am
   
Thanks mate i'll try it out now itself and let u know
Arjun Menon U.K 7-Jun-12 0:53am
   
It worked out fine .. thanks a lot
vangapally Naveen Kumar 7-Jun-12 0:58am
   
welcome .........
Arjun Menon U.K 7-Jun-12 1:05am
   
Hey!! a problem came up if there is any id with value 0 passing '' in IN statement causes that ID to be selected too :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900