问题:
 我用两个标签控件和dataset控件邦定,添加了两个按钮
,通过按钮事件来遍历数据集内容,如何实现......

解决方案 »

  1.   

    用 foreadh(DataTable tab in Dataset.Tables)
    {
      foreadh(DataRow row in tab.Rows)
        {处理一行中的数据}
    }
    遍历记录集中所有数据
      

  2.   

    用 foreach(DataTable tab in Dataset.Tables)
    {
      foreach(DataRow row in tab.Rows)
        {处理一行中的数据}
    }
    遍历记录集中所有数据
      

  3.   

    {
      foreach(DataTable DataTableObj in tempDataSet.tables)//在这段代码中,错误提示是没有定义变量,请问tempDataSet在那里声明,在这个之前,我已经申明了,这里为什么不认啦
       {
         foreach(DataRow  DataRowObj in DataTableObj.Rows)
          {
     tempObj = new TreeContent();
     nCheck = FillTreeObj(tempObj, DataRowObj);
              tempTreeList.Add(tempObj.ID.ToString(), tempObj);
          }
    } 完整代码如下:
    public UNObjectCollection GetTreeList(){
      
      DBAccess DBAccessObj = new DBAccess(m_DBConnectString);
      UNObjectCollection tempTreeList = new UNObjectCollection();
              TreeContent  tempObj ;
      string mQueryString;
              DataSet  tempDataSet;
    //          DataTable DataTableObj;
    //          DataRow  DataRowObj;
              bool nCheck;

      mQueryString = "Select * From Tree Order By ID ";
    try
    {
    tempDataSet = DBAccessObj.ExecuteSelectQuery(mQueryString);
    }
    catch(SqlException e)
    {
        m_Error = e.Message;
    }
               
    if (m_Error == "")
    { foreach(DataTable DataTableObj in  tempDataSet.Tables)
    {
    foreach(DataRow  DataRowObj in DataTableObj.Rows)
    {
      tempObj = new TreeContent();
      nCheck = FillTreeObj(tempObj, DataRowObj);
                  tempTreeList.Add(tempObj.ID.ToString(), tempObj);
    }
    }
     
    }
    tempDataSet = null;
            DBAccessObj = null;
    return tempTreeList;

    }