atlcom 和ado数据库方面的技术(来自gooyan(超级替补) 的帮助)

王朝c#·作者佚名  2006-12-17
窄屏简体版  字體: |||超大  

1.VB客户端 Dim obj As Object

Set obj = CreateObject("AtlCom.OutFun")

Set adoRs = obj.MyMessageBox("aaaa")

2.VC中间层

1.new/projects/ATL COM AppWizard/input AtlCom/OK/Dynamic Link Library(DLL),Suppport MFC,Support

if you want to support MTS,then check MTS/Finish

2.Mouse right Click AtlCom Classes/new Atl Object/simple Object/Names:OutFun,MTS:if you will use

Pool then you check Support IObjectControl and Can be Pooled

3.点IoutFun

把类似

[

object,

uuid(C06F09FA-C905-4E59-AC29-A4137948D8D7),

dual,

helpstring("IOutFun Interface"),

pointer_default(unique)

]

interface IOutFun : IDispatch

{

};

挪到importlib("stdole2.tlb")下面

4.右键点IOutFun,然后Add Method/输入MyMessageBox,parameters:[in]BSTR strInfo(如果需要返回值则为

[out,retval])

再函数中输入:MessageBox(NULL,CString(strInfo),"BOX",MB_OK);

给你一个连接SQL Server得,你把廉节字符串改一下

1.stdafx.h中加入

#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","adoEOF")

2。app文件的InitInstance中加入

if(S_OK!=OleInitialize(NULL))

{

AfxMessageBox("初始化COM组件库错误");

}

下面就是数据库操作

_ConnectionPtr pConn;

_RecordsetPtr pRs;

CString strSQL;

pConn.CreateInstance(__uuidof(Connection));

pConn->CursorLocation=adUseClient;

strSQL="Provider=SQLOLEDB;Server=Gooyan;DataBase=SkillsBox;UID=sa;PWD=aaaaaaaa";

pConn->Open(_bstr_t(strSQL),"","",-1);

pRs.CreateInstance(__uuidof(Recordset));

pRs->CursorLocation=adUseClient;

pRs->PutActiveConnection(pConn.GetInterfacePtr());

pRs1.CreateInstance(__uuidof(Recordset));

pRs1->CursorLocation=adUseClient;

pRs1->PutActiveConnection(pConn.GetInterfacePtr());

strSQL="select * from catalog order by cataid";

pRs->Open(_bstr_t(strSQL),vtMissing,adOpenDynamic,adLockBatchOptimistic,adCmdText);

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航