如何用VC++登录SQL Server数据库?
来源:百度知道 编辑:UC知道 时间:2024/05/13 09:28:05
g_pDBSource = new (CDatabase);
CString strLinkStr;
strLinkStr.Format("DSN=VISCTI;UID=vis;PWD=cti");
try
{
g_pDBSource->OpenEx(strLinkStr,CDatabase::noOdbcDialog);
}
catch(CDBException *e)
{
AfxMessageBox(e->m_strError);
e->Delete();
delete g_pDBSource;
return ;
}
取数据:
if ( g_pDBSource == NULL )
return -2;
CRecordset* rs= NULL ;
try
{
rs=new CRecordset( g_pDBSource );
CString strCount,strTime;
if ( rs->Open( CRecordset::snapshot,sql)!=0 )
{
while( !rs->IsEOF( ) )
{
rs->GetFieldValue((int)0,strCount);
nCount = atol(strCount);
rs->GetFieldValue((int)1,strTime);
switch(index)
{
case 0: //计算总数,构造结构
m_ItemInfo[Counter].strTime = strTime ;
m_ItemInfo[Counter].nCount0 = nCount ;
break;