当前位置:首页 » 多媒体相关

一个嵌套select语句的问题


我的select语句是这样的:  
  sql="select   noteid,usercode,title,ttime,(   select   count(*)   as   nums   from   renotesheet   where   notesheet.noteid=renotesheet.noteid)     from   notesheet   order   by   ttime";  
  oledbconnection   cnn=new   oledbconnection(strcnn);  
  cnn.open();  
  oledbdataadapter   cmd=new   oledbdataadapter(sql,cnn);  
  dataset   ds=new   dataset();  
  cmd.fill(ds,"table1");  
  this.datagrid1.datasource=ds.tables["table1"].defaultview;  
  this.datagrid1.databind();  
  在运行时出现如下问题:  
  至少一个参数没有被指定值。    
  说明:   执行当前   web   请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。    
   
  异常详细信息:   system.data.oledb.oledbexception:   至少一个参数没有被指定值。  
   
  源错误:    
   
   
  行   130: oledbdataadapter   cmd=new   oledbdataadapter(sql,cnn);  
  行   131: dataset   ds=new   dataset();  
  行   132: cmd.fill(ds,"table1");  
  行   133: this.datagrid1.datasource=ds.tables["table1"].defaultview;  
  行   134: this.datagrid1.databind();  
     
   
  在datagrid1中有这5个绑定字段:noteid,usercode,title,ttime,nums.如果去掉嵌套的select语句和绑定字段nums就毫无问题

推荐阅读

  • 中国三大城市调查:百度超过Google列首位 [详细内容]
  • 利用DES加密算法保护Java源代码 [详细内容]
  • 关于小E下面板以及P2K使用和连接的问题 [详细内容]
  • 惠普索贝将建联合实验室 便利多媒体视频编辑 [详细内容]
  • 微软三月内第二次向开发者公布长角牛源代码 [详细内容]
  • 我解决手机不能充电的两种方法 [详细内容]
  • 诺基亚加快3G科研及应用本地化进程 [详细内容]
  • 网友回答:
    网友:yourhoneybee

    将as   nums   返到外面  
      就是sql="select   noteid,usercode,title,ttime,(   select   count(*)   from   renotesheet   where   notesheet.noteid=renotesheet.noteid)   as   nums     from   notesheet   order   by   ttime";  
     

    网友:likika

    sql="select   noteid,usercode,title,ttime,(   select   count(*)   as   nums   from   renotesheet   where   notesheet.noteid=renotesheet.noteid)     from   notesheet   order   by   ttime";  
       
      子查询中缺少表名   notesheet  
      sql="select   noteid,usercode,title,ttime,  
      (   select   count(*)   as   nums   from   notesheet,renotesheet    
      where   notesheet.noteid=renotesheet.noteid)      
      from   notesheet   order   by   ttime";

    网友:alexandria

    try   to   modify   it   as   following:  
       
      sql="select   noteid,usercode,title,ttime,  
      (   select   count(*)   from   renotesheet    
      where   noteid   in   (select   noteid   from   notesheet))   as   nums  
      from   notesheet   order   by   ttime";  
     

    .

    讨论区

    Login