VC控制台程序如何读取INI文件和操作SQL Server数据库 请问VC控制台程序如何读取INI文件和操作SQL Server数据库,有没有相关的例程。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 操作ini文件:GetPrivateProfileIntGetPrivateProfileSection GetPrivateProfileSectionNames GetPrivateProfileString GetPrivateProfileStruct GetProfileInt GetProfileSection GetProfileString WritePrivateProfileSection WritePrivateProfileString WritePrivateProfileStruct WriteProfileSection WriteProfileString #include <sqlfront.h>#include <sqldb.h> dbsqlexec (SQLString) #include <stdio.h>//#include <afxdisp.h>#import "c:\program files\common files\system\ado\msado15.dll" rename ("EOF","adoEOF") no_namespace#define CREATEiNSTANCE(sp,riid) { HRESULT _hr =sp .CreateInstance( __uuidof( riid ) ); \ if (FAILED(_hr)) _com_issue_error(_hr); }#define RsITEM(rs,x) rs->Fields->Item[_variant_t(x)]->Value#define UC (char *)struct InitOle { InitOle() { ::CoInitialize(NULL); } ~InitOle() { ::CoUninitialize(); }} _init_InitOle_; // Global Instance to force load/unload of OLEvoid main(){ _RecordsetPtr spRS; _RecordsetPtr spRSCopy; _ConnectionPtr spCON; try{ CREATEiNSTANCE(spCON,Connection); spCON->ConnectionString = L"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Index.mdb;" L"Persist Security Info=False"; spCON->Open( "", "", "", -1 ); CREATEiNSTANCE(spRS,Recordset) spRS->PutRefActiveConnection( spCON ); spRS->Open("select STATIONID,STATNAME from Station", vtMissing, adOpenKeyset, adLockBatchOptimistic, adCmdUnspecified); CREATEiNSTANCE(spRSCopy,Recordset) spRSCopy->PutRefActiveConnection( spCON ); spRSCopy->Open("select STATIONID,STATNAME from Copy", vtMissing, adOpenKeyset, adLockOptimistic, adCmdUnspecified); while(spRS->adoEOF == false){ printf("StationID = %s StationName = %s \n", UC _bstr_t(RsITEM(spRS,"STATIONID")), UC _bstr_t(RsITEM(spRS,"STATNAME"))); spRSCopy->AddNew(); RsITEM(spRSCopy,"STATIONID") = _bstr_t(UC _bstr_t(RsITEM(spRS,"STATIONID"))); RsITEM(spRSCopy,"STATNAME") = _bstr_t(UC _bstr_t(RsITEM(spRS,"STATNAME"))); spRSCopy->Update(); spRS->MoveNext(); } spRS->Close(); spRSCopy->Close(); spCON->Close(); } catch( _com_error &e){ _bstr_t bstrSource(e.Source()); _bstr_t bs = _bstr_t(" Error: ") + _bstr_t(e.Error()) + _bstr_t(" Msg: ") + _bstr_t(e.ErrorMessage()) + _bstr_t(" Description: ") + _bstr_t(e.Description()); MessageBox(0,bs,bstrSource, MB_OK); } }#undef UC 不通过DSN对SQL SERVER数据库进行连接:m_pConnection->Open("driver={SQLServer};Server=127.0.0.1;DATABASE=vckbase;UID=sa;PWD=139","","",adModeUnknown); 操作ini和sql 数据库都有很多例子的,楼主可以自己找找 操作ini程序的 有很多别人实现的类的 ini文件读写代码 http://www.vckbase.com/code/downcode.asp?id=2609 读写ini的C++类 http://www.vckbase.com/code/downcode.asp?id=2462 超作sql 数据库的例子就更多了拉 MFC CE 动态加载PNG格式的图片 关于硬盘资料获取DeviceIoControl函数 不用mfc实现非阻塞socket编程 如何实现网络监控..散分 画不规则对话框时出的一问题 问:::GDI 的 GdiSetBatchLimit 为什么最大只能设到20 怎么获得已注册的文件类型? 这个程序什么会有异常呢?奇怪呀。 如何利用OLE DB 连接SQL SERVER??? 如何将文件名后缀和应用程序关联起来? 如何控制WebBrowser,并使其提交其中的网页或者操纵其中的文本框等? 请问关于vs2003和vc6开发环境之间的转换问题
GetPrivateProfileInt
GetPrivateProfileSection
GetPrivateProfileSectionNames
GetPrivateProfileString
GetPrivateProfileStruct
GetProfileInt
GetProfileSection
GetProfileString
WritePrivateProfileSection
WritePrivateProfileString
WritePrivateProfileStruct
WriteProfileSection
WriteProfileString
#include <sqldb.h>
dbsqlexec (SQLString)
//#include <afxdisp.h>#import "c:\program files\common files\system\ado\msado15.dll" rename ("EOF","adoEOF") no_namespace#define CREATEiNSTANCE(sp,riid) { HRESULT _hr =sp .CreateInstance( __uuidof( riid ) ); \
if (FAILED(_hr)) _com_issue_error(_hr); }#define RsITEM(rs,x) rs->Fields->Item[_variant_t(x)]->Value
#define UC (char *)
struct InitOle {
InitOle() { ::CoInitialize(NULL); }
~InitOle() { ::CoUninitialize(); }
} _init_InitOle_; // Global Instance to force load/unload of OLEvoid main(){ _RecordsetPtr spRS;
_RecordsetPtr spRSCopy;
_ConnectionPtr spCON;
try{
CREATEiNSTANCE(spCON,Connection);
spCON->ConnectionString = L"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Index.mdb;"
L"Persist Security Info=False";
spCON->Open( "", "", "", -1 );
CREATEiNSTANCE(spRS,Recordset)
spRS->PutRefActiveConnection( spCON );
spRS->Open("select STATIONID,STATNAME from Station", vtMissing, adOpenKeyset,
adLockBatchOptimistic, adCmdUnspecified); CREATEiNSTANCE(spRSCopy,Recordset)
spRSCopy->PutRefActiveConnection( spCON );
spRSCopy->Open("select STATIONID,STATNAME from Copy", vtMissing, adOpenKeyset,
adLockOptimistic, adCmdUnspecified);
while(spRS->adoEOF == false){
printf("StationID = %s StationName = %s \n", UC _bstr_t(RsITEM(spRS,"STATIONID")),
UC _bstr_t(RsITEM(spRS,"STATNAME")));
spRSCopy->AddNew();
RsITEM(spRSCopy,"STATIONID") = _bstr_t(UC _bstr_t(RsITEM(spRS,"STATIONID")));
RsITEM(spRSCopy,"STATNAME") = _bstr_t(UC _bstr_t(RsITEM(spRS,"STATNAME"))); spRSCopy->Update();
spRS->MoveNext();
}
spRS->Close();
spRSCopy->Close();
spCON->Close();
}
catch( _com_error &e){
_bstr_t bstrSource(e.Source());
_bstr_t bs = _bstr_t(" Error: ") + _bstr_t(e.Error()) + _bstr_t(" Msg: ")
+ _bstr_t(e.ErrorMessage()) + _bstr_t(" Description: ")
+ _bstr_t(e.Description());
MessageBox(0,bs,bstrSource, MB_OK);
}
}
#undef UC
Open(
"driver={SQLServer};Server=127.0.0.1;DATABASE=vckbase;UID=sa;PWD=139","","",adModeUnknown
);
读写ini的C++类 http://www.vckbase.com/code/downcode.asp?id=2462