·天新网首页·加入收藏·设为首页
首页|笔记本|手机|数码相机|摄像机|MP3/MP4|主板|内存|显示器|办公|打印机|下载|开发|汽车|学院|业界
硬件|台式机|数码|数字家庭|投影仪|GPS/CPU|显卡|硬盘|服务器|网络|一体机|驱动|源码|游戏|考试|报价
怎样在一个程序中连接两个数据库
http://dev.21tx.com 2005年03月14日

问:SOS 怎样在一个程序中连接两个数据库?数据库在两台机器中,一个是SQL6.5,一个是SQL7.0。

答:

你可以这么做
Transaction mytrans1,mytrans2
mytrans1=Create Transaction
mytrans2=Create Transaction
mytrans1.DBMS="驱动程序类型"
mytrans1.DBParm="这里填连接Sql6.5的字串"
mytrans2.DBMS="驱动程序类型"
mytrans1.DBParm="这里填连接Sql7.0的字串"
connect using mytrans1;
connect using mytrans2;
剩下的你知道该怎么做了?

eg:
Transaction mytrans1,mytrans2
mytrans1=Create Transaction
mytrans2=Create Transaction
mytrans1.DBMS = "ODBC"
mytrans1.AutoCommit = False
mytrans1.DBParm = "ConnectString='DSN=YourDsnforSql6.5DB'"
connect using mytrans1;
IF mytrans1.sqlcode = -1 THEN
Messagebox("",Yourmessage)
disconnect using mytrans1;
halt
end if

mytrans2.DBMS = "ODBC"
mytrans2.AutoCommit = False
mytrans2.DBParm = "ConnectString='DSN=YourDsnforSql7.0DB'"
connect using mytrans2;
IF mytrans2.sqlcode = -1 THEN
Messagebox("",Yourmessage)
disconnect using mytrans2;
halt
end if

//If t65 is a table in your sql6.5 Database,t70 is a table in your sql7.0 Database and
//dw_1 and dw_2 are DataWindow Control ,dwo_sql65 and dwo_sql70 are respectedly DataWindow Object
//for t65 and t70 then
dw_1.dataobject="dwo_sql65"
dw_1.settransobject(mytrans1)
dw_1.retrieve()//It is best to test error
dw_2.dataobject="dwo_sql70"
dw_2.settransobject(mytrans2)
dw_2.retrieve()//It's the same as above
//Then ,you can manipulate the data by dw_1 and dw_2
//Do you understand?

上一篇: 关于Access数据库程序类型越界
下一篇: PB6中怎样实现用代码配置ODBC

Google
 
热点文章
关于我们 | 联系我们 | 广告服务 | 工作机会 | 版权声明 | 欢迎投稿 | 网站地图
Copyright © 2000-2008 , www.21tx.com , All Rights Reserved .
晨新科技 版权所有 Created by TXSite.net