_Connection dbcon;
_Recordset rs;
dbcon.CreateDispatch("ADODB.Connection");
dbcon.Open(m_strConnection,"","",NULL);
rs.CreateDispatch("ADODB.Recordset");
COleVariant vt(m_strTable);
rs.Open(vt,COleVariant(m_strConnection), adOpenStatic,adLockOptimistic, adCmdTable);
LPDISPATCH lpDisp;
lpDisp=rs.GetFields();
ASSERT(lpDisp);
Fields fields;
fields.AttachDispatch(lpDisp);
VARIANT varIndex;
VariantInit(&varIndex);
varIndex.vt=VT_I2;
int nFields=fields.GetCount();
Field field;
CString strFieldName,strFieldType;
long lDefineSize;
for(int i=0;i<nFields;i++)
{
varIndex.iVal=i;
lpDisp=fields.GetItem(varIndex);
field.AttachDispatch(lpDisp);
strFieldName=field.GetName();
lDefineSize=field.GetDefinedSize();
}
field.ReleaseDispatch();
fields.ReleaseDispatch();
rs.Close();
rs.ReleaseDispatch();
dbcon.Close();
dbcon.ReleaseDispatch();
_Recordset rs;
dbcon.CreateDispatch("ADODB.Connection");
dbcon.Open(m_strConnection,"","",NULL);
rs.CreateDispatch("ADODB.Recordset");
COleVariant vt(m_strTable);
rs.Open(vt,COleVariant(m_strConnection), adOpenStatic,adLockOptimistic, adCmdTable);
LPDISPATCH lpDisp;
lpDisp=rs.GetFields();
ASSERT(lpDisp);
Fields fields;
fields.AttachDispatch(lpDisp);
VARIANT varIndex;
VariantInit(&varIndex);
varIndex.vt=VT_I2;
int nFields=fields.GetCount();
Field field;
CString strFieldName,strFieldType;
long lDefineSize;
for(int i=0;i<nFields;i++)
{
varIndex.iVal=i;
lpDisp=fields.GetItem(varIndex);
field.AttachDispatch(lpDisp);
strFieldName=field.GetName();
lDefineSize=field.GetDefinedSize();
}
field.ReleaseDispatch();
fields.ReleaseDispatch();
rs.Close();
rs.ReleaseDispatch();
dbcon.Close();
dbcon.ReleaseDispatch();
解决方案 »
- 重叠IO模型,使用完成例程,怎么使用TransmitFile发送文件?
- 在串口RS485传送资料时遇到的奇怪问题!
- 各位大侠推荐个 免费的软件界面插件
- 虚函数的问题
- 有什么方法可以取得使用指定服务的Application
- 我的程序服务器端用的是WinSock,客户端用的是CSocket,当客户端发文件时,服务器重载的OnClose为什么进不去呢,难道必须都得用Winsock吗
- 我想邀请控Access数据库中的一个表中的全部数据应该怎样做?(注:我用的是odbc)
- AfxMessageBox()..........穷的没分了
- 如何向组件里传入和传出结构?注意,结构里有非简单数据。
- 为了布局美观,想让工具条一开始就dock在窗口的最右边,现在已经是dockable的属性了。想达到如上的效果应该如何做?谢谢。
- 关于托盘图标的问题?
- std中使用ofstream的问题,很奇怪
#define PAUSE printf("\npress any key to exit"); getch();#define _WIN32_DCOM#pragma warning(push)
#pragma warning(disable:4146)
#import "e:\program files\common files\system\ado\MSADO15.DLL" no_namespace rename("EOF", "EndOfFile")
#pragma warning(pop)int main(int argc, char* argv[])
{
_ConnectionPtr m_pConn;
_RecordsetPtr m_pRs;
CoInitializeEx(NULL, COINIT_MULTITHREADED);
_bstr_t bstrConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;"
"Data Source=F:\\lylong\\db1.mdb;Persist Security Info=False";
try{
m_pConn.CreateInstance( __uuidof(Connection) );
m_pRs.CreateInstance( __uuidof(Recordset) );
m_pConn->Open( bstrConnStr, "", "", adConnectUnspecified );
m_pRs->Open( "table1",
m_pConn.GetInterfacePtr(), adOpenForwardOnly, adLockOptimistic, adCmdTable); long lColumn = m_pRs->Fields->Count;
printf("%-12s%-10s%-10s\n", "×Ö¶ÎÃû", "³¤¶È", "ÀàÐÍ");
for( long i=0; i<lColumn; i++ )
{
printf("%-12s%-10d%-10d\n", (char*)m_pRs->Fields->Item[i]->Name,
m_pRs->Fields->Item[i]->DefinedSize,
m_pRs->Fields->Item[i]->Type);
}
m_pRs->Close();
m_pConn->Close();
}catch( _com_error e )
{
printf( "\n%s Error: %ld\r\n"
"%s\r\n"
"%s\r\n",
(char*)e.Source(),
e.Error(),
(char*)e.Description(),
(char*)e.ErrorMessage() );
m_pRs->Close();
m_pConn->Close();
}
CoUninitialize();
PAUSE;
return 0;
}
printf("%-12s%-10s%-10s\n", "字段名", "长度", "类型");:)
{
if(m_pDB.IsOpen())
m_pDB.Close();
m_pDB.Open(GetDefaultDBName(),FALSE,FALSE,MYPASSWORD);
}
catch(CDaoException* e)
{
DisplayDaoException(e);
e->Delete();
return;
}
CDaoTableDef m_OpenTable(&m_pDB);
try
{
m_OpenTable.Open(this->m_strUniqueName);//确定打开什么表
}
catch(CDaoException* e)
{
DisplayDaoException(e);
e->Delete();
return;
}
int nFields;
CDaoFieldInfo fieldInfo;
try
{
nFields=m_OpenTable.GetFieldCount();
for(int j=0;j<nFields;j++)
{
m_OpenTable.GetFieldInfo(j,fieldInfo);
// rListCtrl.InsertItem( j, fieldInfo.m_strName);//行头
rListCtrl.InsertColumn( j,fieldInfo.m_strName , LVCFMT_LEFT, 200, 0 );
}
}
catch(CDaoException* e)
{
DisplayDaoException(e);
e->Delete();
return;
}
m_OpenTable.Close();
LoadColumnWidths(); //查询
enum DataTypeEnum
{
adEmpty = 0,
adTinyInt = 16,
adSmallInt = 2,
adInteger = 3,
adBigInt = 20,
adUnsignedTinyInt = 17,
adUnsignedSmallInt = 18,
adUnsignedInt = 19,
adUnsignedBigInt = 21,
adSingle = 4,
adDouble = 5,
adCurrency = 6,
adDecimal = 14,
adNumeric = 131,
adBoolean = 11,
adError = 10,
adUserDefined = 132,
adVariant = 12,
adIDispatch = 9,
adIUnknown = 13,
adGUID = 72,
adDate = 7,
adDBDate = 133,
adDBTime = 134,
adDBTimeStamp = 135,
adBSTR = 8,
adChar = 129,
adVarChar = 200,
adLongVarChar = 201,
adWChar = 130,
adVarWChar = 202,
adLongVarWChar = 203,
adBinary = 128,
adVarBinary = 204,
adLongVarBinary = 205,
adChapter = 136,
adFileTime = 64,
adPropVariant = 138,
adVarNumeric = 139,
adArray = 8192
};