CSV的导出 CSV的导出,谁能给我点资料啊。我是完全不懂得阿。有两种方法的参数,一种是一个类作为参数,一个是传入一个sql语句这种的。请教阿!!!!!!!!!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 导出一个CSV文件阿。难道就没有人知道吗???? 导出一个CSV文件,难道就没有人知道吗。希望达人能够教教我啊。 //strPath:csv文件的所在目录和csv文件名,如"C:\temp\123.csv"_ConnectionPtr CFMCSApp::OpenDataBaseConnection(CString strPath){ CString strConn; //CIniFile file("DC_GPSServer.ini"); strConn.Format("Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=%s;Extensions=asc,csv,tab,txt;Persist Security Info=False",strPath); BSTR bstrConn = strConn.AllocSysString(); _ConnectionPtr pConn; try { HRESULT hr; pConn.CreateInstance(__uuidof(Connection)); pConn->ConnectionString = bstrConn; pConn->ConnectionTimeout = 0; hr = pConn->Open(_T(""), // privder and data source _T(""), //user name of db _T(""), //password of user adOpenUnspecified //Does not specify the type of cursor. ); if( FAILED(hr)) { ::SysFreeString(bstrConn);// LogInfoTime("打开数据库连接失败"); return NULL; } } catch(_com_error &e) { ::SysFreeString(bstrConn); _bstr_t bstrDescription(e.Description()); CString msg; msg.Format("Description = %s", (LPCSTR) bstrDescription); MessageBox(NULL,msg,m_strAppTitle,MB_OK); return NULL; } ::SysFreeString(bstrConn); return pConn;}_RecordsetPtr CFMCSApp::DB_GetRecordset(_ConnectionPtr pConn,CString strSQL){ if(pConn==NULL) { MessageBox(NULL,_T("The Connection to DB is invalid!"),m_strAppTitle,MB_OK); return NULL; } HRESULT hr; BSTR bstrSQL; _RecordsetPtr pRstRet = NULL; bstrSQL = strSQL.AllocSysString(); try { pRstRet.CreateInstance(__uuidof(Recordset)); hr = pRstRet->Open(bstrSQL, _variant_t((IDispatch *) pConn, true), adOpenStatic/*adOpenDynamic*/, adLockOptimistic, adCmdText); } catch(_com_error &e) { _bstr_t bstrDescription(e.Description()); //MessageBox(NULL,(LPCSTR)bstrDescription,m_strAppTitle,MB_OK);// LogComError(e); return NULL; } ::SysFreeString(bstrSQL); if( FAILED(hr)) {// LogInfoTime("执行SQL语句错误,SQL:%s", strSQL); return NULL; } return pRstRet;}//赶紧给我分吧!!! MFC中的SelectObject问题 VC++6.0将磁盘.exe文件写入程序进程的地址空间内并执行之 数据库表的密码类型如何转换为CString型或者是char[400] 如何在VC工程中引入大量的C文件? 菜鸟100分请教一个关于打印预览简单的问题~ idispatch error 3149 是什么错误~ 为什么我在CListCtrl里面排序,lParam1和lParam2总是为0 ? 使能工具栏的某项 有关文件映像问题! MFC42.DLL你在哪? callback function 求助:在SDI中动态创建控件无法响应事件!急~~
_ConnectionPtr CFMCSApp::OpenDataBaseConnection(CString strPath)
{
CString strConn;
//CIniFile file("DC_GPSServer.ini");
strConn.Format("Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=%s;Extensions=asc,csv,tab,txt;Persist Security Info=False",strPath);
BSTR bstrConn = strConn.AllocSysString();
_ConnectionPtr pConn;
try
{
HRESULT hr;
pConn.CreateInstance(__uuidof(Connection));
pConn->ConnectionString = bstrConn;
pConn->ConnectionTimeout = 0;
hr = pConn->Open(_T(""), // privder and data source
_T(""), //user name of db
_T(""), //password of user
adOpenUnspecified //Does not specify the type of cursor.
);
if( FAILED(hr))
{
::SysFreeString(bstrConn);
// LogInfoTime("打开数据库连接失败");
return NULL;
}
}
catch(_com_error &e)
{
::SysFreeString(bstrConn); _bstr_t bstrDescription(e.Description());
CString msg;
msg.Format("Description = %s", (LPCSTR) bstrDescription);
MessageBox(NULL,msg,m_strAppTitle,MB_OK);
return NULL;
}
::SysFreeString(bstrConn);
return pConn;
}_RecordsetPtr CFMCSApp::DB_GetRecordset(_ConnectionPtr pConn,CString strSQL)
{
if(pConn==NULL)
{
MessageBox(NULL,_T("The Connection to DB is invalid!"),m_strAppTitle,MB_OK);
return NULL;
}
HRESULT hr;
BSTR bstrSQL;
_RecordsetPtr pRstRet = NULL;
bstrSQL = strSQL.AllocSysString();
try
{
pRstRet.CreateInstance(__uuidof(Recordset));
hr = pRstRet->Open(bstrSQL, _variant_t((IDispatch *) pConn,
true), adOpenStatic/*adOpenDynamic*/, adLockOptimistic, adCmdText);
}
catch(_com_error &e)
{
_bstr_t bstrDescription(e.Description());
//MessageBox(NULL,(LPCSTR)bstrDescription,m_strAppTitle,MB_OK);
// LogComError(e);
return NULL;
}
::SysFreeString(bstrSQL); if( FAILED(hr))
{
// LogInfoTime("执行SQL语句错误,SQL:%s", strSQL);
return NULL;
}
return pRstRet;
}
//赶紧给我分吧!!!