本文介绍了数据表仅加载保存的最后一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

请帮帮我



以下代码应返回以下结果




Hi all
Please help me

my following code should return the following result


//gridview1             //gidview2
pland                   countf

14/08/2013                 2
18/08/2013                 0







但结果是保存在grid数据表中的最后一条记录如下







but the result is the last record saved in " grid" datatable as following


//gridview1             //gidview2
14/08/2013                 0
18/08/2013







这是我的代码






This is my code

protected void Butshow_Click(object sender, EventArgs e)
    {
        DateTime datefrom = DateTime.Parse(Textfrom.Text);// textbox for date from
        DateTime dateto = DateTime.Parse(Textto.Text);// textbox for date to 

        // get date in gridview 
        inp.plandatefrom = datefrom;
        inp.plandateto = dateto;
        dt = inp.gridshow(); // this method used stored peocedure that take from and to date to get date between and worked well 
        GridView1.DataSource = dt;
        GridView1.DataBind();
       
// here I want to get other value using the  date output from previous datatable "dt"
         foreach (DataRow row in dt.Rows)
        {
       
      DataTable grid = new DataTable();
       
       
            inf.plandat = DateTime.Parse(row[0].ToString()); 
            grid = inf.gridshowfor();// this method take the date and get result

            GridView2.DataSource = grid;
            GridView2.DataBind(); // here is the problem , the result get only last record saved in datatable " 

                
         }

推荐答案

protected void Butshow_Click(object sender, EventArgs e)
        {
            DateTime datefrom = DateTime.Parse(Textfrom.Text);// textbox for date from
            DateTime dateto = DateTime.Parse(Textto.Text);// textbox for date to 

            // get date in gridview 
            inp.plandatefrom = datefrom;
            inp.plandateto = dateto;
            dt = inp.gridshow(); // this method used stored peocedure that take from and to date to get date between and worked well 
            GridView1.DataSource = dt;
            GridView1.DataBind();

            // here I want to get other value using the  date output from previous datatable "dt"
            var mainGrid = new DataTable();
            mainGrid.Columns.Add("Count");
            foreach (DataRow row in dt.Rows)
            {

                DataTable grid = new DataTable();


                inf.plandat = DateTime.Parse(row[0].ToString());
                grid = inf.gridshowfor();// this method take the date and get result

                foreach (DataRow dr in grid.Rows)
                {
                    if (dr != null && dr[0] != null)
                    {
                        var mainRow = mainGrid.NewRow();
                        mainRow["Count"] = dr[0];
                        mainGrid.Rows.Add(mainRow);
                    }
                }

                GridView2.DataSource = mainGrid;
                GridView2.DataBind(); // here is the problem , the result get only last record saved in datatable " 
            }
        }


这篇关于数据表仅加载保存的最后一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 19:57