I am fairly new to powerbuilder 12.5 and i cant find much tutorials on database management on SQL 2008. I need to connect to it via code like in VB.NET vs2008

Dim con As New SqlConnection

Con.connectionstring = "Data Source=servername;Initial Catalog=user;Integrated Security=True"

I need to select, insert, update and delete data...

Any help on code samples

解决方案

Datawindows

Most database work with PB is done using datawindows. After you create a new datawindow, you set up your select statement in it.

Then you add a datawindow control to your form and set the control to use the datawindow that you created (using the properties window or even in code).

Then in your code you can retrieve the data and issue commands via the datawindow control and it will automatically handle the insert, update and delete sql statements for you.

For example:

dw_1.retrieve() // dw_1 is the name of the datawindow control

// insert a row

dw_1.insertrow(0)

// delete a row

dw_1.deleterow(1)

// update all changed rows

dw_1.update(true, true)

(see the PB help for more info on what the values in parenthesis mean)

DB connections

PowerBuilder has a built-in transaction object that you can use called sqlca:

sqlca.dbms = "SNC SQL Native Client(OLE DB)"

sqlca.servername = "servername"

sqlca.dbparm = "Database='user',Provider='SQLNCLI10',Identity='@@IDENTITY',TrustedConnection=1"

Then to connect to this database you do:

connect using sqlca;

You can disconnect with:

disconnect using sqlca;

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐