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

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐