我是一个Asp.net初学者,我在页面中拖拽了一个SqlDataSource,可是我怎莫在后台代码里取得SqlDataSource返回的结果记录集中的指定记录上指定字段的值?----------------------
下面是天涯老大发的:
----------------------
dsTitles = new SqlDataSource();
        dsTitles.ConnectionString = ConfigurationManager.ConnectionStrings["pubs"].ConnectionString;
        dsTitles.SelectCommand = "Select title_id, title, type, notes from Titles";
        dsTitles.EnableCaching = true;
        dsTitles.SqlCacheDependency = "pubs:Titles";        IEnumerator enumerator = dsTitles.Select(new DataSourceSelectArguments()).GetEnumerator();        while (enumerator.MoveNext())
        {
            Response.Write("<br/>title: " + ((DataRowView)enumerator.Current).Row["title"].ToString());
        }
-----------------------------------------------------------------------------
我的问题是:这个是遍历了一遍,我只想取第一个怎么办?

解决方案 »

  1.   

    dsTitles = new SqlDataSource();
    dsTitles.ConnectionString = ConfigurationManager.ConnectionStrings["pubs"].ConnectionString;
    dsTitles.SelectCommand = "Select title_id, title, type, notes from Titles";
    dsTitles.EnableCaching = true;
    dsTitles.SqlCacheDependency = "pubs:Titles";IEnumerator enumerator = dsTitles.Select(new DataSourceSelectArguments()).GetEnumerator();while (enumerator.MoveNext()){
        Response.Write("<br/>title: " + ((DataRowView)enumerator.Current).Row["title"].ToString());
        break;//添加break在取得第一个后就跳出循环
    }
      

  2.   

    The Reset method brings the enumerator back to before the first element in the collection.