在一个表中,"select id from table1 where a=1 " 得到的id有一到多条记录,假设是3条记录(record[3])为1,2,3,第一、C#里怎么取到这三条记录?用数组保存吗?取得的这些记录在另一个表需要作出判断,"select count(*) from table2 where b=record[0] and endtime IS NULL" 如果count(*)有记录则退出, 没有则"select count(*) from table2 where b=record[1] and endtime IS NULL"如果count(*)有记录则退出,以此类推,第二该怎么写第二个判断比较高效合理?谢谢!

解决方案 »

  1.   

    若是SqlDataReader drwhile(dr.Read())
    {
      //...
    }若是DataTable dtfor(int i=0;i<dt.Rows.Count;i++)
    {
      //...
    }
      

  2.   

    是DataReader,我不用数组,单纯用一个变量去取语句值就出错,数组该怎么定义while(dr.Read()),跟下面的判断怎么衔接。
      

  3.   

    select aa.id from table1  as aa inner join table2 as cc on cc.b=aa.Id where aa.a=1 and cc.endtime IS NULL
    这是高效的 
      

  4.   

    难道不能用连接查询一次搞定?
    select COUNT(*) from table1 t1 INNER JOIN table2 t2 ON t1.id=t2.b where t1.a=1
      

  5.   

    哦,sql高级用法没用过,明天回去试试,谢谢。