日期:2014-05-18  浏览次数:20447 次

怎样在VC6.0控制台上写SQL语句
怎样在VC6.0控制台上写SQL语句,请高手举个例子,我在自学数据库

------解决方案--------------------
#import "c:\program files\common files\system\ado\msado15.dll " no_namespace rename( "EOF ", "adoEOF ")
int main(int argc, char* argv[])
{
printf( "This sample shows you how to access BLOB via ADO and store it as file "
"The second field of the database is BLOB\n "
"If it works, it is writen by masterz,\n "
"otherwise I don 't know who write it\n ");
CoInitialize(NULL);
try
{
_ConnectionPtr pConn( "ADODB.Connection ");
_RecordsetPtr pRst( "ADODB.Recordset ");
_variant_t varBLOB;
pConn-> Open(_bstr_t( "Driver={Microsoft Access Driver (*.mdb)};DBQ=GetChunk.mdb "), " ", " ",adConnectUnspecified);
pRst-> Open(_bstr_t( "BlobTable "),_variant_t((IDispatch *) pConn, true),
adOpenKeyset, adLockOptimistic, adCmdTable);
pRst-> MoveFirst();
//long lDataLength = pRst-> Fields-> Item[1L]-> ActualSize;
//varBLOB = pRst-> Fields-> Item[1L]-> GetChunk(lDataLength);
_StreamPtr stream;
stream.CreateInstance( "ADODB.Stream ");
_variant_t varOptional(DISP_E_PARAMNOTFOUND,VT_ERROR);
stream-> raw_Open(varOptional, adModeUnknown, adOpenStreamUnspecified,NULL,NULL);
stream-> put_Type(adTypeBinary);
stream-> Write(pRst-> GetFields()-> GetItem(_variant_t((long)1))-> GetValue());
stream-> SaveToFile( "test.txt ",adSaveCreateOverWrite);
printf( "save stream to file finished\n ");
stream-> Close();
pRst-> Close();
pConn-> Close();
}
catch (_com_error &e)
{
printf( "Description = '%s '\n ", (char*) e.Description());
}
::CoUninitialize();
return 0;
}