读书人

请问:Access中的数据读到treectrl中

发布时间: 2012-12-17 09:31:40 作者: rapoo

请教:Access中的数据读到treectrl中,并显示
我的数据库: 其中,id设为自动编号,grandpaName为总跟节点,PareName二级节点
id SysName PareName GrandPaName
1 南京 江苏 中国
2 苏州 江苏 中国
3 无锡 江苏 中国
4 杭州 浙江 中国
5 宁波 浙江 中国

6 篮球 球类 运动
7 足球 球类 运动
8 健身 室内 运动
9 台球 室内 运动

(1-5为一个树,6-9为另外一个树,根节点分别为中国 ,运动)
我的代码如下:
Cstring strGrandPaName;

HTREEITEM m_Root;//一代根节点
m_Root=m_tree.InsertItem((LPCTSTR)strGrandPaName,0,0);
// HTREEITEM m_child; //二代分支
//HTREEITEM m_childChild; //三代分支

ADOConn m_adoConn;
//_RecordsetPtr m_pRs1;

m_adoConn.OnInitADOConn();
CString sql,sql1,ChildName,ChildChName;
sql="select * from NNewModel where GrandPareName= '"+strGrandPaName+"'";
m_pRs=m_adoConn.GetRecordSet(_bstr_t(sql));
//m_pRs->MoveFirst(); // 直接MoveFirst()
while (!m_pRs->adoEOF)
{
ChildName=(char*)(_bstr_t)m_pRs->GetCollect("PareName");
if(ChildName!=strGrandPaName) //此处为我判断的 跟问题无关
{
m_child=m_tree.InsertItem((LPCTSTR)ChildName,1,1,m_Root);


//方案B
ChildChName=(char*)(_bstr_t)m_pRs->GetCollect("SysName");
m_childChild=m_tree.InsertItem((LPCTSTR)ChildChName,2,2,m_child);
m_pRs->MoveNext();
CString stt; //用来储存m_pRs指向的下一个PareName的内容,与当前比较,若相同则为同一级树下的子 //节点,否则,插入新的二级母节点
stt=(char*)(_bstr_t)m_pRs->GetCollect("PareName");
while (stt==ChildName)
{
ChildChName=(char*)(_bstr_t)m_pRs->GetCollect("SysName");
m_childChild=m_tree.InsertItem((LPCTSTR)ChildChName,2,2,m_child);
m_pRs->MoveNext();
stt=(char*)(_bstr_t)m_pRs->GetCollect("SysName");
}



}
m_pRs->MoveNext();
}
m_adoConn.ExitConn();

m_tree.Expand(m_Root,TVE_EXPAND);
}


当 显示 “中国”的树时,还算正常,可是,“运动”时,弹出错误对话框;;
Running error!

This application has requisted the RunTime to terminate it in an anusual way,
Please contact the application's support team for more information



还有一个问题,出现错误是否跟我的id自动编号有关系,别且当我的id设为自动编号时,貌似即使我把数据手动清空了,id还不会归零,一直加下去,该如何解决 ,求各位大侠指点

------解决方案--------------------


CString ChildName 是用于获取二级节点的内容,
CString ChildChName是为了获取三级子节点的内容
[解决办法]
Running error表示你没抓异常,先抓个_com_error看看错误消息是什么吧

读书人网 >VC/MFC

热点推荐