日期:2014-05-18  浏览次数:20714 次

asp.net从数据库返回值 放到dataset为什么没有值
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语句的时候 程序就能接收到值

------解决方案--------------------
用sql profiler跟踪一下看看实际执行的sql语句
------解决方案--------------------
用sql profiler跟踪,把sql语句复制出来 在sql的查询分析器中 执行看结果