select bknote from books where bookid=(select bookid from booksort where bookname='abc')我的2张表books和booksort 表中都有bookid字段,现在连接2个表,我页面上知道bookname是变动的,所以,abc用变量代替。我的变量名字叫 bkname,各位给个写法。最好按照我这个格式,水平比较凹,太复杂了弄不懂。   XXXX 应该改成 :select bknote from books where bookid=(select bookid from booksort where bookname= XXXX  )
            

解决方案 »

  1.   

    这个意思?string sql = string.Format("select bknote from books where bookid=(select bookid from booksort where bookname= '{0}')",bkname); 
      

  2.   

    select bknote from books where bookid in (select bookid from booksort where bookname= XXXX  ) 
      

  3.   

    "select bknote from books where bookid=(select bookid from booksort where bookname= '"+bkname"'"
      

  4.   

    "select bknote from books where bookid=(select bookid from booksort where bookname= '"+bkname+"'"少个加号
      

  5.   

    string str="";
    string sql="select bknote from books where bookid=(select bookid from booksort where bookname='"+str+"')" ;
      

  6.   

    "select bknote from books where bookid=(select bookid from booksort where bookname= '"+bkname+"'" 
      

  7.   

    select * from books where bookid in (select distinct bookid from booksort where bookname='')
      

  8.   

    select bknote from books where bookid in (select bookid from booksort where bookname= '"+abc+"')
    恩!应该上这样的了!没问题啊!你要的结果已经搞定了啦!
      

  9.   

    select bknote from books where bookid=(select bookid from booksort where bookname='abc') 
    本身就是错误的表达. 除非把 = 改成 in .如果不这样改. 那么这样也行,不过,不知道是不是你要的效果:
    select bknote from books where bookid=(select top 1 bookid from booksort where bookname='abc') SQL字符串拼接更简单...  没什么难的,注意单引号成对出现就够了.LS已经有人说出正确答案,我就不说了.
      

  10.   

    select bknote from books where bookid in (select bookid from booksort where bookname= 'abc')这样写不错,就是这样写的
      

  11.   

    他的意思其实是两个表无刷新相关联,用dropdownlist或者另一个list控件来显示,在选第一个的时候,第二个显示相应的数据,看你的sql代码是对的呀.不过前面你要定义一下abc
      

  12.   

    1:
    string sql=string.Format("select bknote from books a where exists(select b.bookid from booksort b where a.bookid=b.bookid and b.bookname='{0}'"),bkanme); 
    2:
    string sql=string.Format("select a.bknote from books a left join booksort b on a.bookid=b.bookid where b.bookname='{0}'",bkname);
      

  13.   

    要防sql注入
    select A.bknote from books  A ,booksort B where A.bookid=B.bookid and B.bookname= @bookname 
      

  14.   

    myCommand.Parameters.Add("@bookname", OleDbType.VarChar, 80).Value = "abc";
      

  15.   

    select bknote from books where bookid=('"+ +"');
      

  16.   

    select bknote from books where bookid in(select bookid from booksort where bookname='"+abc+"')
      

  17.   

    如果name确保对以唯一的bookid,上面写的没有错如果name一对多,那么就为in
      

  18.   

    结贴了,abc是我的值,我要把它换成变量,需要加两边加上“+” ,我就差了这个东西。其他方法可能也有行的,我没试。  试了试 那个 '{0}')带参数的报错了。分主要给第一个给出正确答案的了啊。