c++和sql servel连接实例

来源:百度知道 编辑:UC知道 时间:2024/06/07 07:25:43
c++和SQL servel数据库之间是如何进行连接的,请给出能运行实例好么?
另外我用的编程软件是VS2008

也可以用ODBC数据源和其他的,具体找本教程书来看看吧

VC++6.0里,可以用孙鑫视频教程里ADO的方法。
像下面这样的。 具体找教程来看看吧
LPCTSTR lpConnString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=PLStat";

sql.Format("select * from commontable where matchdate = '%s' and teamname = '%s' ", stat->date, stat->teamname);

lpCmd = sql.GetBuffer(sql.GetLength());

CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Connection));
pConn->ConnectionString=lpConnString;

try{
pConn->Open("", "", "", adConnectUnspecified);
pRst = pConn->Execute(lpCmd, NULL, adCmdText);
}
catch(...)
{
//ret = 0;
AfxMessageBox("Database Operate Failed!");
return -1;
}

i