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); } }
{
foreadh(DataRow row in tab.Rows)
{处理一行中的数据}
}
遍历记录集中所有数据
{
foreach(DataRow row in tab.Rows)
{处理一行中的数据}
}
遍历记录集中所有数据
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;
}