DotNetFresh

博客园 首页 新随笔 联系 订阅 管理
    1.在1.1中,经常图方便,这样进行DataGrid的绑定操作:
            
SqlConnection con = new SqlConnection(@"server=localhost;User ID=sa;Password=sa;database=Test;Connection Reset=FALSE");
            SqlCommand command 
= new SqlCommand("select * from tempTable",con);
            SqlDataAdapter adapter 
= new SqlDataAdapter(command);

            DataSet ds 
= new DataSet();
            adapter.Fill(ds);

            dgTest.DataSource 
= ds;
            dgTest.DataBind();

        在2.0中,使用如下相同代码:
        SqlConnection con = new SqlConnection(@"Data Source=localhost;Initial Catalog=Test;User ID=sa;Password=sa");
        SqlCommand command 
= new SqlCommand("select  * from tempTable", con);
        SqlDataAdapter adapter 
= new SqlDataAdapter(command);

        DataSet ds 
= new DataSet();
        adapter.Fill(ds);

        GridView1.AllowPaging 
= true;
        GridView1.PageSize 
= 20;
        GridView1.DataSource 
= ds;
        GridView1.DataBind();

            如上绑定你会发现未绑定任何数据.后单步跟踪发现,asp.net2.0在DataSet ds = new DataSet();的时候,会自动的在里面添加一张表,所以写GridView1的数据源的时候必须写成GridView1.DataSource = ds.Table[1].DefaultView才能正确绑定.不解...另外这种问题只出现在Asp.net应用程序中.如果你新建一个Console程序,便没这个问题.难道是asp.net2.0处理引擎的关系???上网找答案未果.哪位达人研究比较深入?给点意见??
        2. 上面的表tempTable是个百W级的表,在1.1中进行绑定显示大约只需要8秒,(我的表只有两个字段).但是相同代码在2.0中绑不出来(起码我出去WC-大号,抽了跟烟回来绑定结果都没出来).MS宣称在2.0中针对DataSet进行了特别的优化,包括全新的索引,更强大的DataTable等等...那为什么会出现这个情况?(最开始,我是使用SalDataSource 进行的绑定发现出不来,以为是SalDataSource 的问题,但换成原始方式还是不行).到底是DataSet的问题?还是 adapter.Fill(ds);的问题?还是GridView的问题???


        零零碎碎研究了半天,未果.....达人~~~呼叫达人~~~     
       

posted on 2005-08-31 17:43  DotNetFresh  阅读(1847)  评论(3编辑  收藏  举报