Beispiel #1
0
BOOL ADOConn::ExcuteSQL(_bstr_t bstrSQL)
{
	try
	{
		//连接数据库,如果Connection对象为空 重新连接
		if (m_pConnection==NULL)
		{
			OnInitADOConn();
		}
		//创建记录集对象
		m_pRecordset.CreateInstance(__uuidof(Recordset));
		m_pRecordset = m_pConnection->Execute(bstrSQL,NULL,adCmdText);
	}
	catch(_com_error e)
	{
		std::cout<<e.Description();
	}
	if (m_pRecordset != NULL)
	{
		return true;
	}
	else
	{
		return false;
	}
}
Beispiel #2
0
BOOL ADOConn::ExecuteSQL(_bstr_t bstrSQL)//执行SQL操作语句
{
	try
	{
		if(m_pCon==NULL)
			OnInitADOConn();//连接数据库
		m_pCon->Execute(bstrSQL,NULL,adCmdText);//执行SQL
		return true;
	}
	catch(_com_error e)//捕捉异常
	{
		AfxMessageBox(e.Description());
		return false;
	}
}
Beispiel #3
0
_RecordsetPtr& ADOConn::GetRecordSet(_bstr_t bstrSQL)//执行SQL查询语句
{
	try
	{
		if(m_pCon==NULL)
			OnInitADOConn();
		m_pRs.CreateInstance("ADODB.Recordset");//创建记录集
		m_pRs->Open(bstrSQL,m_pCon.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
	}
	catch(_com_error e)//捕捉异常
	{
		AfxMessageBox(e.Description());
	}
	return m_pRs;//返回结果集
}
BOOL  Model::ExecuteSQL(_bstr_t bstrSQL)
{
	_variant_t RecordsAffected;
	try
	{
		//是否已连接数据库
		if (m_pConnection == NULL)
			OnInitADOConn();
		m_pConnection->Execute(bstrSQL, NULL, adCmdText);
		return true;
	}
	catch (_com_error e)
	{
		printf(e.Description());
		return false;
	}
}
BOOL DataConnection::ExecuteSQL(_bstr_t bstrSQL)
{	
	try
	{	
		if(m_pConnection == NULL) //初始化连接
		{
			OnInitADOConn();
		}
		
		m_pConnection->Execute(bstrSQL,NULL,adCmdText);
		return true;
	}
	catch(_com_error e) //失败
	{
		MessageBox(NULL,e.Description(),"Information",MB_ICONINFORMATION | MB_OK);
		return false;
	}
}
_RecordsetPtr& Model::GetRecordSet(_bstr_t bstrSQL)
{
	try
	{
		//连接数据库,如果connection对象为空,则重新连接数据库
		if (m_pConnection == NULL)
			OnInitADOConn();
		//创建记录集对象
		m_pRecordset.CreateInstance(__uuidof(Recordset));
		//取得表中的记录
		m_pRecordset->Open(bstrSQL, m_pConnection.GetInterfacePtr(), adOpenDynamic, adLockOptimistic, adCmdText);
	}
	catch (_com_error e)
	{
		printf(e.Description());
	}
	//返回记录集
	return m_pRecordset;
}
//Get record of database
bool DataConnection::GetRecordSet(_RecordsetPtr &m_pRecordset , _bstr_t bstrSQL)
//第一个参数是引用类型,也就是传出参数,可看做函数的返回值,第二个参数是SQL语句,是输入。
{
	try
	{	
		if(m_pConnection==NULL) //初始化连接
			OnInitADOConn();
		
		m_pRecordset.CreateInstance(__uuidof(Recordset));
		m_pConnection->CursorLocation = adUseClient;
		
		m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
		return true;
	}
	
	catch(_com_error e) //失败
	{		
		MessageBox(NULL,e.Description(),"提示",MB_ICONINFORMATION | MB_OK);
		return false;
	}
}
Beispiel #8
0
//执行查询
_RecordsetPtr& ADOConn::GetRecordSet(_bstr_t bstrSQL)
{
	try
	{
		//连接数据库,如果Connection对象为空 重新连接
		if (m_pConnection==NULL)
		{
			OnInitADOConn();
		}
		//创建记录集对象
		m_pRecordset.CreateInstance(__uuidof(Recordset));
		//取得表中的记录
		m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
	}
	catch(_com_error e)
	{
		std::cout<<e.Description();
	}
	//m_pConnection.Release();
	return m_pRecordset;
}
Beispiel #9
0
// 打开记录集
_RecordsetPtr& ADOConn::GetRecordSet(_bstr_t bstrSQL)
{
//TODO: insert return statement here
try
{
if (m_pConnection==NULL)
{
OnInitADOConn();
}
//创建记录对象
m_pRecordset.CreateInstance(__uuidof(Recordset));
//取得表中记录
m_pRecordset->Open(bstrSQL,m_pConnection.GetInterfacePtr(),adOpenDynamic,
adLockOptimistic,adCmdText);
}
catch (_com_error e)
{
e.Description();
}
return m_pRecordset;
}
Beispiel #10
0
// 执行SQL语句,Insert Update _variant_t
BOOL Cdata::ExecuteSQL(_bstr_t bstrSQL)
{
	//    _variant_t RecordsAffected;
	try
	{
		// 是否已经连接数据库
		if (m_pConnection == NULL)
			OnInitADOConn();
		// Connection对象的Execute方法:(_bstr_t CommandText, 
		// VARIANT * RecordsAffected, long Options ) 
		// 其中CommandText是命令字串,通常是SQL命令。
		// 参数RecordsAffected是操作完成后所影响的行数, 
		// 参数Options表示CommandText的类型:adCmdText-文本命令;adCmdTable-表名
		// adCmdProc-存储过程;adCmdUnknown-未知
		m_pConnection->Execute(bstrSQL, NULL, adCmdText);
		return true;
	}
	catch (_com_error e)
	{
		AfxMessageBox(e.Description());
		return false;
	}
}
Beispiel #11
0
Model::Model()
{
	OnInitADOConn();
}