2. 建表
codbase.CommandText=“{call CREATABLE (?) }”
codbase.CommandType = adCmdText
codbase.Name = “CREATABLE”
’设定OutPut的参数
Set param = codbase.CreateParameter(“flag”, adInteger, adParamOutput)
codbase. Parameters. Append param
Set codbase. ActiveConnection = cndbase
codbase. Execute
If codbase. Parameters(0) = 0 Then
myexit = MsgBox(“建表成功!”, vbOKOnly, “程序提示:”)
Else
myexit = MsgBox(“建表失败!”, vbOKOnly, “错误提示:”)
Endif
……
3. 修改
rsdbase.
Open“worker”,cndbase,adOpenDynamic,adLockPessimistic,adCmdTable
rsdbase. MoveFirst
cndbase. BeginTrans
’在记录集中进行循环更改
Do Until rsdbase.EOF
’增加20元职务代码为1的人员的工资
If rsdbase! duty = 1 Then
rsdbase! salary = rsdbase! salary + 20
End If
rsdbase. MoveNext
Loop
rsdbase.UpdateBatch
……
4. 统计
StrSQL = “Select avg(salary), sum(salary) from worker”
rsdbase. CursorLocation = adUseClient
rsdbase. Open StrSQL,cndbase
salaryavg = rsdbase(0) ’平均工资
salarysum = rsdbase(1) ’工资总和
……
rsdbase .Close
5. 存储过程creatable. sql
CREATE PROCEDURE dbo.creatable(@return_value integer output)
AS
Begin
Create table Workerdb..Worker
( code nchar(4) not null ,
name char(8) not null ,
year nchar(4) ,
month nchar(2) ,
day nchar(2) ,
salary numeric(18,2) ,
duty nchar(1)
If @@error != 0
begin
select @return_value = 1
End
Else
Begin
select @return_value = 0
End
return
End