sqlexec.cpp
来自「数据库开发」· C++ 代码 · 共 75 行
CPP
75 行
//SQLExec.cpp
/**************************************************************************
* 文件名:SQLExec.cpp
*
* SQL语句处理以及COM错误分析:
*
* PrintComError(_com_error &e) - COM错误分析
* StringToInt(CString s) -字符串转换为整型
* ExecSQL(LPCTSTR strSql) -执行数据库语句
*
*
*************************************************************************/
#include "stdafx.h"
#include "SQLExec.h"
#include "..\AirMonitor.h"
void WINAPI PrintComError(_com_error &e)
{
_bstr_t bstrSource(e.Source());
_bstr_t bstrDescription(e.Description());
// Print Com errors.
printf("Error\n");
printf("\tCode = %08lx\n", e.Error());
printf("\tCode meaning = %s\n", e.ErrorMessage());
printf("\tSource = %s\n", (LPCSTR) bstrSource);
printf("\tDescription = %s\n", (LPCSTR) bstrDescription);
}
int StringToInt(CString s)
{
int nReturn = 0;
char cc[10];
wsprintf(cc, "%s", s);
nReturn = atoi(cc);
return nReturn;
}
void ExecSQL(LPCTSTR strSql)
{
_RecordsetPtr pRst = NULL;
TESTHR(pRst.CreateInstance(__uuidof(Recordset)));
CAirMonitorApp* pApp = (CAirMonitorApp*)AfxGetApp();
pApp->m_curConfig.ADOExec(pRst, _variant_t(strSql));
}
float StringToFloat(CString s)
{
float fReturn = 0;
char cc[10];
wsprintf(cc, "%s", s);
fReturn = (float)atof(cc);
return fReturn;
}
COleDateTime StringToTime(CString s)
{
int nYear, nMonth, nDay,nHour,nMinute,nSecond;
CString ss;
ss = s.Left(4);
nYear = StringToInt(ss);
ss = s.Mid(5,2);
nMonth = StringToInt(ss);
ss = s.Mid(8,2);
nDay = StringToInt(ss);
nHour = StringToInt("00");
nMinute = StringToInt("00");
nSecond = StringToInt("00");
COleDateTime t(nYear, nMonth, nDay,nHour, nMinute,nSecond);
return t;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?