使用 MFC, sql server2000 开发图书管理系统 同样的程序,完全相同的数据库,不同的机器 为什么别的电脑可以运行 我的运行却出现如题的错误!!! 错误:unhandled exception in 文件名.exe (KERNEL32.DLL):0xE06D7363:Microsoft C++ Exception ,使用ADO连接的sql server2000,将ADO封装为一个类,代码我会贴在回复区 拜托大侠帮帮小弟 作业要完不成啦!
解决方案 »
- 谁知道如何用资源ID建立wxImage或wxBitmap?
- 同一代码在VC6和vc2003输出竟然不一样???
- 请问这种类型的窗口要怎样取?
- 请问怎样得到应用程序所在的目录.用 GetCurrentDirectory(256,path),当打开新目录,它就不是了!
- unsigned char m_char(unsigned char) m_double;转化问题
- 图像处理的高手请进:jpg的分割与组合问题?
- TREE控件问题 在线提问
- 已知一维指针和数据区大小,想变成指定长宽的二维指针,怎麽办?
- 知道ToolBar按钮的奥秘吗?
- 关于STL的初级问题,急
- 怎么查找一个已安装的软件所在的绝对路径??
- CDialogBar::Create
//打印调用ADO控件时产生的详细错误信息
void dump_com_error(_com_error &e)
{
CString ErrorStr;
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
ErrorStr.Format( "\n\tADO Error\n\tCode = %08lx\n\tCode meaning = %s\n\tSource = %s\n\tDescription = %s\n\n",
e.Error(), e.ErrorMessage(), (LPCTSTR)bstrSource, (LPCTSTR)bstrDescription );
//在调试窗口中打印错误信息,在Release版中可用DBGView查看错误信息
::OutputDebugString((LPCTSTR)ErrorStr);
#ifdef _DEBUG
AfxMessageBox(ErrorStr, MB_OK | MB_ICONERROR);
#endif
}try
{
//你的ADO代码
}
catch(_com_error& e)
{
dump_com_error(e);
}
//ADO 头文件#import "C:\Program Files\Common Files\System\ado\msado15.dll"no_namespace rename("EOF","adoEOF")
////////////////////////////////////////////////////////////////
class ado
{
public:
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
public:
ado();//构造函数直接连接数据库
// virtual ~ado();
void close();
bool MovePrevious();//向上移动
bool MoveLast();//最后一条
bool MoveNext();//向下移动
bool MoveFirst();//最后一条
int GetRecordCount();//获取记录个数
bool Open(CString srecordset,UINT adCmd);
void GetErrors(_com_error eErrors);//获取错误信息
CString GetFieldValue(CString Field);//获取字段信息
bool Move(int nRecordNum);//移动记录
void ExecuteSQL(CString SQL);//执行SQL语句
void rstOpen(CString TSQL);//打开记录集};//ADO。cppado::ado()
{
::CoInitialize(NULL);//ado是基于COM技术要进行初始化
try
{
m_pConnection.CreateInstance(__uuidof(Connection));
_bstr_t strConnect="Provider=SQLOLEDB;Database=Library;uid=sa;pwd=123;";
m_pConnection->Open(strConnect,"","",0);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
} bool ado::Open(CString srecordset,UINT adCmd)
{
try
{
m_pRecordset=m_pConnection->Execute((_bstr_t)srecordset,NULL,adCmd);
}
catch(_com_error e)
{
this->GetErrors(e);
return false;
}
return true;
}
//用于返回记录的个数
int ado::GetRecordCount()
{
int nCount=0;
try{
m_pRecordset->MoveFirst();
}
catch(...)
{
return 0;
}
if(m_pRecordset->adoEOF)
return 0;
while(!m_pRecordset->adoEOF)
{
m_pRecordset->MoveNext();
nCount=nCount+1;
}
m_pRecordset->MoveFirst();
return nCount;
}
//这个函数用来获取执行SQL语句时的出错信息 void ado::GetErrors(_com_error eErrors)
{
ErrorsPtr pErrors=m_pConnection->GetErrors();
if(pErrors->GetCount()==0)
MessageBox(NULL,eErrors.ErrorMessage(),"错误",MB_OK|MB_ICONEXCLAMATION);
else
{
for(int i=0;i<pErrors->GetCount();i++)//如果有多条语句,使用该循环输出所有错误
{
_bstr_t desc=pErrors->GetItem((long)i)->GetDescription();//貌似有问题
MessageBox(NULL,desc,"错 误",MB_OK|MB_ICONEXCLAMATION); }
}
} void ado::rstOpen(CString TSQL)
{
try
{
_bstr_t bstrSQL=TSQL.AllocSysString();
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open(bstrSQL,(IDispatch *)m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
}
catch(_com_error e)
{
m_pRecordset=m_pConnection->Execute((_bstr_t)TSQL,NULL,adCmdText);
}
}
//获取记录集指定列的值的代码设置如下
CString ado::GetFieldValue(CString Field)
{
_variant_t Thevalue;
CString temp;
Thevalue=m_pRecordset->GetCollect((_bstr_t)Field);
if(Thevalue.vt==VT_EMPTY||Thevalue.vt==VT_NULL)
temp="";
else
{
temp=(char*)(_bstr_t)Thevalue;
temp.TrimRight();
temp.TrimLeft();
}
return temp;
}
//指向记录集的游标向上移动一条
bool ado::MovePrevious()
{
try
{
m_pRecordset->MovePrevious();
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return false;
}
return true;
}
/*代码导读 1._bstr_t 是字符串数据结构,和CSting类同等重要,主要用于 COM程序开发。
2. _variant_t 用于COM程序的数据结构变量
3. _com_error COM程序的出错信息数据结构*/
//指向记录集的游标移到指定行处的代码设置如下
bool ado::Move(int nRecordNum)
{
try
{
if(!m_pRecordset->BOF)
{
m_pRecordset->MoveFirst();
}
m_pRecordset->Move(nRecordNum);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return false;
}
return true;
}
//指向记录集的游标向下移一条的代码设置如下:
bool ado::MoveNext()
{
try
{
m_pRecordset->MoveNext();
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return false;
}
return true;
} bool ado::MoveFirst()
{
try
{
m_pRecordset->MoveFirst();
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return false;
}
return true;
} bool ado::MoveLast()
{
try
{
m_pRecordset->MoveLast();
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
return false;
}
return true;
} void ado::ExecuteSQL(CString TSQL)
{
try
{
m_pConnection->Execute((_bstr_t)TSQL,NULL,adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
} void ado::close()
{
m_pRecordset->Close();
m_pConnection->Close();
m_pRecordset=NULL;
m_pConnection=NULL;
::CoUninitialize();
}
你看看这个会不会对你有帮助
http://blog.csdn.net/xianglitian/archive/2010/05/22/5617173.aspx