?? dataconn.cpp
字號:
// DataConn.cpp: implementation of the DataConn class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Predict.h"
#include "DataConn.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
DataConn::DataConn()
{
}
DataConn::~DataConn()
{
}
void DataConn::DataInit()
{
::CoInitialize(NULL); //初始化COM環境變量
try
{
m_pConnection.CreateInstance(__uuidof(Connection));//定義指向定義ADO對象的指針類型
_bstr_t strConnect="Provider=MSDASQL.1;Persist Security Info=False;Data Source=data";
m_pConnection->Open(strConnect,"","",adModeUnknown);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
}
_RecordsetPtr DataConn::GetRecordset(_bstr_t sql)
{
try
{
if(m_pConnection==NULL)
DataInit();
m_pRecordset.CreateInstance(__uuidof(Recordset));
m_pRecordset->Open(sql,m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
return m_pRecordset;
}
BOOL DataConn::SQLExecute(_bstr_t sql)
{
try
{
if(m_pConnection==NULL)
DataConn();
m_pConnection->Execute(sql,NULL,adCmdText);
return true;
}
catch(_com_error e)
{
::AfxMessageBox(e.Description());
return false;
}
}
void DataConn::ExitSql()
{
if(m_pRecordset!=NULL)
m_pRecordset->Close();
m_pConnection->Close();
::CoUninitialize();
}
BOOL DataConn::SetData(float x,float y)
{
DataInit();
_bstr_t sql="select * from dataTable";
_RecordsetPtr recordset;
recordset=GetRecordset(sql);
recordset->AddNew();
recordset->PutCollect("input",_variant_t(x));
recordset->PutCollect("out",_variant_t(y));
recordset->Update();
ExitSql();
return true;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -