我的数据要一行一行的添加,也就我获取一次数据我就调用我写的DataTable添加行的方法添加一次,
但是这样这样无论我添加几次都只拿到了最后一天记录,有没有什么好的方法可以让我获取所有的
这题我给五十分,最先给出正确 答案的我给30分

解决方案 »

  1.   

       foreach (string name in xtraTableColumnName)
                {
                        if (!xtraTable.Columns.Contains(name))
                        {
                            DataColumn xtraDc = new DataColumn(name);
                            xtraTable.Columns.Add(xtraDc);
                        }
                }
                xtraTable.AcceptChanges();
      

  2.   

    例子代码要修改   
    for (int j=0;j< GridView1 .Rows .Count ; j ++)
                        {
                          Pid  = mydt.Rows[j][2].ToString();
                           if (Pid == i)  //如果符合
                           {
                                str += ",'" + setime + "','" + Msg + "','0')";
                                if (balcls.sqlcom(str))
                                {
                                    //Response.Write("<script>alert('xxxx');</script>");                            }
                           }
                           else
                           {
                               continue;
                           }
                        }
      

  3.   

    你可以用
    Session["mytable"]=Tb1;或者用Cache都可以.
      

  4.   

    ps:我用的C# 
     这是我现在写的代码:
    public DataSet  InsertDataTable(string CustomerID,string Rolls,string WeightQty,string LengthQty,string empID,string prodID)
    {
    DataSet dataset = daset;
        DataTable table=dt;
    //定义表结构
    table.Columns.Add("CustomerID",typeof(System.String));
    table.Columns.Add("ProdID",typeof(System.String));
    table.Columns.Add("Rolls",typeof(System.String));
    table.Columns.Add("WeightQty",typeof(System.String));
    table.Columns.Add("LengthQty",typeof(System.String));
    table.Columns.Add("Creater",typeof(System.String));
    DataRow datarow =table.NewRow();
    //添加新行
    datarow[0]=CustomerID;
    datarow[1]=prodID;
    datarow[2]=Rolls;
    datarow[3]=WeightQty;
    datarow[4]=LengthQty;
    datarow[5]=empID;
    table.Rows.Add(datarow);
    dataset.Tables.Add(table);
    return dataset; }
      

  5.   

    把datatable里面的东西负给session
    session["tablevalue"]=dt
      

  6.   


    再加一个Session["mytable"]=Tb1就是正解楼主应给他们两个
      

  7.   

    Accesslr 是楼主我自己  那个代码也是我给的  我做的winform应用程序没有session
      

  8.   

    从楼主的代码看,你这样是永远都只能得到一个只有一行的dataTable,思路得改改://以下代码未测试,可能有问题你自己改改
    private DataTable _cacheTable;public DataTable cacheTable() //返回一个定义好结构的DataTable,如果为空则初始化一个
    {
       get
       {
         if(_cacheTable == null)
         {
             _cacheTable= new DataTable();
             _cacheTable.Columns.Add("CustomerID",typeof(System.String)); 
             _cacheTable.Columns.Add("ProdID",typeof(System.String)); 
             _cacheTable.Columns.Add("Rolls",typeof(System.String)); 
             _cacheTable.Columns.Add("WeightQty",typeof(System.String)); 
             _cacheTable.Columns.Add("LengthQty",typeof(System.String)); 
             _cacheTable.Columns.Add("Creater",typeof(System.String));          
         }
         return _cacheTable;
       }
    }public void InsertDataTable(string CustomerID,string Rolls,string WeightQty,string LengthQty,string empID,string prodID) 
    //注意这个函数不返回值,也可以返回true false之类标志插入成功与否,Dataset不是必须的
    {
         DataTable table = _cacheTable;
         DataRow datarow =table.NewRow(); 
         //添加新行 
         datarow[0]=CustomerID; 
         datarow[1]=prodID; 
         datarow[2]=Rolls; 
         datarow[3]=WeightQty; 
         datarow[4]=LengthQty; 
         datarow[5]=empID; 
         table.Rows.Add(datarow);
    } 以下函数为你最终要使用这个插入了多行的DataTable的地方
    public void f(){
         for(int i=0;i<cacheTable.rows.count;i++){
             ....
         }
    }
      

  9.   

    你需要定义一个全局变量的DataTable或者用ViewState来存放DatatTable
      

  10.   

    我现在问一下 DataTable 能不能做那种追加效果啊,
    就是我首先添加一行,我添加第二行的时候我只追加不覆盖
      

  11.   

    Mark2Win 兄台的是对的 按照先前承诺 我给他30 其余的论功行赏
    谢谢各位给我解决问题!