从一个不在另一个表中的表中检索数据

时间:2014-03-06 08:46:57

标签: asp.net sql

sq = "select roomno,blockname from roommanage where roomno not in( select *from availableroom)";
ds = dc.filldata(sq);
GridView1.DataSource = ds.Tables["t1"];
GridView1.DataBind();

有一个错误:

Only one expression can be specified in the select list when the subquery is not introduced with EXIST

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

在你的“不在”中应该只返回1列。请尝试以下代码。

sq = "select roomno,blockname from roommanage where roomno not in( select id from availableroom)";
    ds = dc.filldata(sq);
    GridView1.DataSource = ds.Tables["t1"];
    GridView1.DataBind();

答案 1 :(得分:0)

两列试试这个

    sq = "SELECT roomno,blockname FROM roommanage 
WHERE roomno NOT IN( SELECT id FROM availableroom) 
AND blockname NOT IN(SELECT yourcolumn FROM blockname)";
ds = dc.filldata(sq);
GridView1.DataSource = ds.Tables["t1"];
GridView1.DataBind();