1

我是 PowerBuilder 的新手。

我想从 MSAccess 表中检索数据并将其更新为相应的 SQL 表。我无法为 MSAccess 创建永久 DSN,因为我必须选择具有相同表信息的不同 MSAccess 文件。我可以为 SQL 服务器创建一个永久的 DSN。

请帮助我在选择 MSAccess 文件时动态创建 DSN,并使用 PowerBuilder 将所有表数据推送到 SQL。

如果可能的话,还要提供完整的 PowerBuilder 代码来完成问题。

4

4 回答 4

4

In Access we strongly suggest not using DSNs at all as it is one less thing for someone to have to configure and one less thing for the users to screw up. Using DSN-Less Connections You should see if PowerBuilder has a similar option.

于 2009-10-10T02:09:46.160 回答
1

您想要执行 Tony 引用的 DSNLess 连接。我在PBDJ展示了一个示例,并在 Sybase 的 CodeXchange 上提供了一个代码示例。

于 2009-12-11T02:47:34.457 回答
1
  • Create the DSN manually in the ODBC administrator
  • Locate the entry in the registry
  • Export the registry syntax into a .reg file
  • Read and edit the .reg file dynamically in PB
  • Write it back to the registry using PB's RegistrySet ( key, valuename, valuetype, value )

Once you've got your DSN set up, there are many options to push data from one database to the other.

You'll need two transaction objects in PB, each pointing to its own database. Then, you could use a Data Pipeline object to manage the actual data transfer.

于 2009-10-08T07:39:46.143 回答
0

我正在使用此代码,试试吧!

//// Profile access databases accdb format
SQLCA.DBMS = "OLE DB"
SQLCA.AutoCommit = False
SQLCA.DBParm = "PROVIDER='Microsoft.ACE.OLEDB.12.0',DATASOURCE='C:\databasename.accdb',DelimitIdentifier='No',CommitOnDisconnect='No'"

Connect using SQLCA;
If SQLCA.SQLCode = 0 Then
    Open ( w_rsre_frame )   
else
    MessageBox ("Cannot Connect to Database", SQLCA.SQLErrText )
End If

或者

//// Profile access databases mdb format
transaction aTrx
long resu
string database 
database = "C:\databasename.mdb" 
aTrx  = create transaction 
aTrx.DBMS = "OLE DB" 
aTrx.AutoCommit = True 
aTrx.DBParm = "PROVIDER='Microsoft.Jet.OLEDB.4.0',DATASOURCE='"+database+"',PBMaxBlobSize=100000,StaticBind='No',PBNoCatalog='YES'"
connect using aTrx ;
if atrx.sqldbcode = 0 then
    messagebox("","Connection success to database")
else 
    messagebox("Error code: "+string(atrx.sqlcode),atrx.sqlerrtext+ " DB Code Error: "+string(atrx.sqldbcode))
end if
// do stuff...
destroy atrx
于 2013-05-14T22:19:21.307 回答