VC控制台程序如何读取INI文件和操作SQL Server数据库

wiber 2005-05-18 04:34:09
请问VC控制台程序如何读取INI文件和操作SQL Server数据库,有没有相关的例程。
...全文
204 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
AntonlioX 2005-07-19
  • 打赏
  • 举报
回复
超作sql 数据库的例子就更多了拉
AntonlioX 2005-07-19
  • 打赏
  • 举报
回复
操作ini程序的 有很多别人实现的类的

ini文件读写代码 http://www.vckbase.com/code/downcode.asp?id=2609
读写ini的C++类 http://www.vckbase.com/code/downcode.asp?id=2462
oyljerry 2005-07-19
  • 打赏
  • 举报
回复
操作ini和sql 数据库都有很多例子的,楼主可以自己找找
BuZhang_AP97091 2005-07-19
  • 打赏
  • 举报
回复
不通过DSN对SQL SERVER数据库进行连接:

m_pConnection->
Open(
"driver={SQLServer};Server=127.0.0.1;DATABASE=vckbase;UID=sa;PWD=139","","",adModeUnknown
);


BuZhang_AP97091 2005-07-19
  • 打赏
  • 举报
回复
#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 OLE

void 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
findit 2005-07-01
  • 打赏
  • 举报
回复
#include <sqlfront.h>
#include <sqldb.h>
dbsqlexec (SQLString)
hjcy_2002 2005-05-18
  • 打赏
  • 举报
回复
krh2001的完全正确,支持
idAnts 2005-05-18
  • 打赏
  • 举报
回复
操作ini文件:
GetPrivateProfileInt
GetPrivateProfileSection
GetPrivateProfileSectionNames
GetPrivateProfileString
GetPrivateProfileStruct
GetProfileInt
GetProfileSection
GetProfileString
WritePrivateProfileSection
WritePrivateProfileString
WritePrivateProfileStruct
WriteProfileSection
WriteProfileString

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧