asp.net 从数据库存储过程执行两次sql 返回两个table(也就是两次数据) 然后程序里用dataset 接收 然后dataset的 tables[1]有值,tables[0]怎么没有 但是table 已经被创建了 就是没有值 但是我执行存储过程 是有值的啊
程序            DataSet ds = SqlHelper.ConSelect(SqlHelper.ConnectionStringHy, "Hy_getcostselect", para);
 public static DataSet ConSelect(string connstr, string proc, SqlParameter[] para)
        {            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = connstr;
                if (conn.State == ConnectionState.Closed)
                {
                    conn.Open();
                }
                using (SqlCommand comm = new SqlCommand())
                {
                    comm.Connection = conn;
                    comm.CommandType = CommandType.StoredProcedure;
                    comm.CommandText = proc;
                    foreach (SqlParameter sp in para)
                    {
                        comm.Parameters.Add(sp);
                    }
                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = comm;
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    return ds;
                }
            }        }
存储过程:
set @sqlstr=N' select max(ces.autoid) as autoid,max(ces.缴费单据编号) as payNumber,max(ces.缴费项目) payItem,sum(ces.缴费单价) as payPrice,sum(ces.应交费用) as yingJiao,sum(ces.实际缴费) as shiJiao,max(ces.费用所属时间) as Stime from HYFORHT.dbo.charge_EditSubordinate ces
where ces.缴费项目  in('+@nameID+')  and ces.缴费单据编号= '+char(39)+@Jcode+char(39)+' and 费用所属时间='+char(39)+@fytime+char(39)+ ' group by ces.缴费项目'

execute sp_executesql @sqlstr set @sqlstr=N'select 楼盘编号 as bh,室号 as sh from HYFORHT.dbo.房产基本信息 where 房产编号='+char(39)+@FCnumber+char(39)

execute sp_executesql @sqlstr
并且两条器语句有数据返回 第二条就能接收到
感觉程序应该没什么,因为我用一条普通的sql语句的时候 程序就能接收到值

解决方案 »

  1.   

    调过来也不行 到底是怎么回事 更相信是  sql的 bug
      

  2.   

    之前是第一个表没有数据,调过来是第二个表没有数据,对吧?那就是sql没查到数据
      

  3.   

    用sql profiler跟踪一下看看实际执行的sql语句
      

  4.   

    不是 调过来 也是第二个表没数据 反正就是 长的那条sql语句没数据 ,我再数据库里用 临时表 各种办法 都是获取不到 , 对了 刚才我改变了sql执行办法, 就是之前用的是 execute的办法执行字符串方式,然后我改为直接 select * from 了 然后 我用sql查询分析器调用存储过程的时候(给定了真实数据)
    execute Hy_getcostselect @strtime='2012-01-01',
    @endtime='2012-01-31',
    @WhereFY='电费,水费,',
    @FCnumber='FC1109280001',
    @mytype='1'
    能够查询出来数据 然后我用程序调用的 报语法错误 ,难道是 用sql查询分析器调用的 跟 c#调用的 存储过程 会有不同sql语句产生sql profiler 怎么用啊   用sql profiler能够看到c#所执行的存储过程?
      

  5.   

    用sql profiler跟踪,把sql语句复制出来 在sql的查询分析器中 执行看结果 
      

  6.   

    他怎么用呢   sql profiler  我新建跟踪 点击运行 出来好多东西现在不是 前面绑定的事  是在DAL层中 用dataset  然后直接 dataset.tables[0].rows.count 到这就没有数据了