SQLCA.DBMS=\SQLCA.AutoCommit=false
SQLCA.DBParm=\connect; //执行连接数据库的操作 //判断连接动作是否成功 if SQLCA.SQLCode <>0 then
MessageBox(\提示\数据库连接失败!\ Return //若失败,则返回,不再继续执行程序 end if
2、编写一段PowerBuilder中的嵌入式SQL语句,向表employee的Address和Name列分别插入数据“济南”、“王伟”。 答案:
insert into \ (\values(\济南\王伟\
3、用PowerScript语言编程实现1*2*3*?*100的计算,并将结果用消息框输出。 答案: long I long S=1
31
for I=1 to 100
S=S*I next
Messagebox(\?*100的结果是:\
4、编程求N!(N!=N×(N-1)×?×3×2×1)。 答案: 代码如下 integer i dec n,s=1
n = dec(sle_1.text) for i=1 to n s=s*i next
sle_2.text=string(s)
5、编写自定义函数,实现三个数中得到最大的数。 答案:
打开函数画板,进行自定义函数操作。代码如下: integer z if a > b then z = a else
32
z = b end if if c > z then z = c end if return z
6、编程求1+3+5+7+??+99 答案: integer s,i s=0
for i=1 to 99 step 2 s=s+i next
st_1.text=string(s)
7、在PowerBuilder中判断数据库操作是否成功,若成功提交事务,失败则显示错误原因并撤消事务。 答案:
if SQLCA.SQLCode=0 then commit;
messagebox(\提示\,\成功\else
33
messagebox(\提示\ rollback; end if
8、按所给条件写出PowerBuilder与数据库连接的代码。条件如下: (1)数据库管理系统是ODBC (2)数据库是tcdb (3)用户代码是db (4)数据库口令是ok (5)登陆代码是sa (6)登陆口令是dht007 (7)服务器名无
(8)数据库参数为:ConnectString='DSN=mydb;UID=db;PWD=ok' (9)如果连接不成功则显示“注意,不能连接到数据库上” 答案:
SQLCA.DBMS='ODBC' SQLCA.DataBase='tcdb' SQLCA.UserId='db' SQLCA.DBPass='ok' SQLCA.LogId='sa' SQLCA.LogPass='dht007' SQLCA.ServerName=''
SQLCA.DBParm=\
34
if SQLCA.SQLCode<>0 then
MessageBox(\注意\,\不能连接到数据库上\ return end if
35