数据集 
    DataTable dtSubReqInfo = new DataTable();
   dtSubReqInfo = (DataTable)Session[this.strSubReqSessionName];
   DataSet dsSubReqInfo = new DataSet();
   dsSubReqInfo.Tables.Add(dtSubReqInfo);
改为:
   DataTable dtSubReqInfo = new DataTable();
   dtSubReqInfo = (DataTable)Session[this.strSubReqSessionName];
   DataSet dsSubReqInfo = new DataSet();
   dsSubReqInfo.Tables.Add(dtSubReqInfo.Copy()); 

解决方案 »

  1.   

    應該要copy()
    ds.Tables.Add(dt.Copy());
      

  2.   

    在往DataTable增加Table的时候DataSet已经包含了该表。
      

  3.   

    我还想问一下 为什么我的dataset永远只保存一行记录
    //全局变量
    public DataSet dataset= new DataSet();
    public DataTable tables;
    /// <summary>
    /// 返回一个定义好结构的DataTable,如果为空则初始化一个 
    /// </summary>
    /// <returns></returns>
    public DataTable cacheTable() 

    if(tables==null)
    {
    tables = new DataTable(); 
    tables.Columns.Add("CustomerID",typeof(System.String)); 
    tables.Columns.Add("ProdID",typeof(System.String)); 
    tables.Columns.Add("Rolls",typeof(System.String)); 
    tables.Columns.Add("WeightQty",typeof(System.String)); 
    tables.Columns.Add("LengthQty",typeof(System.String)); 
    tables.Columns.Add("Creater",typeof(System.String));  
    tables.Columns.Add("JobSheetID",typeof(System.String));  
    }
    return tables; 

    /// <summary>
    /// 这个函数不返回值 给table的每一列赋值
    /// </summary>
    /// <param name="CustomerID"></param>
    /// <param name="Rolls"></param>
    /// <param name="WeightQty"></param>
    /// <param name="LengthQty"></param>
    /// <param name="empID"></param>
    /// <param name="prodID"></param>
    public void InsertDataTable(string CustomerID,string Rolls,string WeightQty,string LengthQty,string empID,string prodID,string jobSheetNo) 

    DataTable table = cacheTable(); 
    DataRow datarow =tables.NewRow(); 
    //添加新行 
    datarow[0]=CustomerID; 
    datarow[1]=prodID; 
    datarow[2]=Rolls; 
    datarow[3]=WeightQty; 
    datarow[4]=LengthQty; 
    datarow[5]=empID; 
    datarow[6]=jobSheetNo;
    table.Rows.Add(datarow); 
    dataset.Tables.Add(table.Copy());
    // MessageBox.Show(dataset.Tables[0].Rows.Count.ToString());
    // for(int i=0;i<dataset.Tables[0].Columns.Count;i++)
    // {
    // MessageBox.Show(dataset.Tables[0].Rows[0][i].ToString());
    // }

    我的做法是拿一行数据 就条用一次
      

  4.   

    InsertDataTable里重新定义了table