我用ADO+ACCESS,写一个树!我在初使化树叉的函数(ShowTree())中,调用了
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open("SELECT * FROM NoteTree",_variant_t((IDispatch*)theApp.m_pConnection,true),/*adOpenDynamic*/adOpenStatic,adLockOptimistic,adCmdText);
语句,一都都正常。但当我“单击树叉显示详细信息”这个函数中要再次调用m_pRecordset时,却出错了,在这个函数中必须调用m_pRecordset->Close,然后重新m_pRecordset->Open……
可是一调用m_pRecordset->Close就出错,在单击树叉出错时就显示“RunTime Error”的错误。abnormal program termination!
PS:编译时没有出错!
这是怎么回事儿,请大家帮帮我!
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open("SELECT * FROM NoteTree",_variant_t((IDispatch*)theApp.m_pConnection,true),/*adOpenDynamic*/adOpenStatic,adLockOptimistic,adCmdText);
语句,一都都正常。但当我“单击树叉显示详细信息”这个函数中要再次调用m_pRecordset时,却出错了,在这个函数中必须调用m_pRecordset->Close,然后重新m_pRecordset->Open……
可是一调用m_pRecordset->Close就出错,在单击树叉出错时就显示“RunTime Error”的错误。abnormal program termination!
PS:编译时没有出错!
这是怎么回事儿,请大家帮帮我!
解决方案 »
- int型10进制转换为uint16型16进制
- 如何能够显示一个表呢??
- 请问大虾:哪儿有以下三本书的电子版下载?中英文均可
- 哪里有VC++技术内幕的例子源码下载
- 在用ADO开发编译时,总是提示msado15.tlh(405) : warning C4146: unary minus operator applied to unsigned type, result still unsigne
- 我在ATL中创建了一个MTS组件,请问在VC中如何测试
- 关于文件Create的问题
- 请问编程如何创建一个拨号连接的快捷方式
- vc怪事
- 大虾们,请问初学VC究竟看哪几本参考书最好、最有用????
- 哪位大虾用vc 6 编译过openoffice的源码?请帮忙!!
- 有没有什么工具可以将rm转为Mp3或wav的?
可以再if(m_pRecordset->state)
m_pRecordset->Close();
先探测一下状态
加上if(m_pRecordset->state)还不行!
我用Try 和Catch试了一下,给出错误信息是“Invalid Pointer”,意思是“无效指针”,对吧!这是怎么回事儿呢!
OnSelectTree中的m_pRecordset就说是指针无效,而在ShowTree中的m_pRecordset就没问题!大家看看是怎么回事儿啊! 我要是不解决这个问题,我就完了!!!!555555555~~~void CXTOutBarCtrl1::OnSelectTree(NMHDR* pNMHDR, LRESULT* pResult){
NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
///获得当前项的句柄,然后你就可以为所欲为了,嘿嘿
HTREEITEM hTreeItem = ((CMainFrame *)AfxGetMainWnd())->m_wndTreeCtrl.GetSelectedItem ();
//((CMainFrame *)AfxGetMainWnd())->m_wndTreeCtrl.SelectItem(hTreeItem); ///设定当前项
CString S1 = ((CMainFrame *)AfxGetMainWnd())->m_wndTreeCtrl.GetItemText(hTreeItem); ///用GetItemText()函数取得选定项的文本:
_variant_t vName;
CMYPropertyPage cpg; ///获得选中项的文本赋给m_NodeName
cpg.m_PEdit1=((CMainFrame *)AfxGetMainWnd())->m_wndTreeCtrl.GetItemText(hTreeItem); ///下面演示了用ADO建立一个数据库的记录集的方法。
///注意_variant_t,_bstr_t 两个类型和其它类型的转换
S1="SELECT * FROM NodeTree where NoteText='"+S1+"'";
//and ParentID ='S2' ";
try
{
// if(m_pRecordset->State)// m_pRecordset->Close(); m_pRecordset->Open((_variant_t)S1,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
m_pRecordset->MoveFirst();
vName=m_pRecordset->GetCollect("NoteText");
cpg.m_PEdit2=(LPCTSTR)(_bstr_t)vName;
}
catch(_com_error e)///捕捉异常
{
CString errormessage; errormessage.Format("数据库Error!\r\n错误信息:%s",e.ErrorMessage()); AfxMessageBox(errormessage);///显示错误信息
} }
*pResult = 0;
}
void CXTOutBarCtrl1::ShowTree()
{
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open("SELECT * FROM NoteTree",_variant_t((IDispatch*)theApp.m_pConnection,true),/*adOpenDynamic*/adOpenStatic,adLockOptimistic,adCmdText);
// m_bSuccess = TRUE; //m_pRecordset->MoveLast(); //vNoteID = m_pRecordset->GetCollect("NoteID");
//NoteCount = vNoteID.lVal; //最大ID号
HTREEITEM hItem,hSubItem[255]; m_pRecordset->MoveFirst(); ((CMainFrame *)AfxGetMainWnd())->m_wndTreeCtrl.DeleteAllItems(); while(!m_pRecordset->adoEOF)///这里为什么是adoEOF而不是EOF呢?还记得rename("EOF","adoEOF")这一句吗?
{
vNoteID = m_pRecordset->GetCollect("NoteID");
vNoteText = m_pRecordset->GetCollect("NoteText");
vParentID = m_pRecordset->GetCollect("ParentID");
//父级项句柄是 hSubItem[vParentID.lVal]
hItem= hSubItem[vParentID.lVal];
item=vNoteID.lVal;
hSubItem[item]=((CMainFrame *)AfxGetMainWnd())->m_wndTreeCtrl.InsertItem((LPCTSTR)(_bstr_t)vNoteText,hItem);
//设置树叉内含数据
//((CMainFrame *)AfxGetMainWnd())->m_wndTreeCtrl.SetItemData( hSubItem[item], vParentID.lVal);
m_pRecordset->MoveNext();///移到下一条记录
}
if(m_pRecordset->State) m_pRecordset->Close();
} catch(_com_error e)///捕捉异常
{
CString errormessage; errormessage.Format("读取数据库失败!\r\n错误信息:%s",e.ErrorMessage()); AfxMessageBox(errormessage);///显示错误信息 }
或者不用CLOSE 改用null
if(m_pRecordset->State)
m_pRecordset->Close();
m_pRecordset.Release();
m_pRecordset = NULL;
以后再建m_pRecordset.CreateInstance();
再使用
但在单击树时,出现如下错误:
IDispatch error #3127这是怎么回事儿!