标题:写了3个代码都说我 “begin”附近语法错误,之前也是这么写的,也没有找到错 ...
只看楼主
Littlewen
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2020-6-12
结帖率:100%
 问题点数:0 回复次数:1 
写了3个代码都说我 “begin”附近语法错误,之前也是这么写的,也没有找到错误,求助!!
存储过程:
程序代码:
USE [WeMeet]
GO
/****** Object:  StoredProcedure [dbo].[usp_Delete]    Script Date: 06/15/2020 22:10:02 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER proc [dbo].[usp_Delete]  

@name char(50)

as begin
declare @err int
delete from Player where pName=@name
set @err=@@ERROR
if(@err!=0)return -1
return 0
end



VB代码
程序代码:
Private Sub Command1_Click()
  Dim cmd As String, cc As Long
  On Error GoTo ErrorHandler
   If MsgBox("真的要删除玩家'" & Trim(DataGrid1.Columns(0).Text) & '吗?", vbYesNo, "信息") <> vbYes Then Exit Sub

    If DataGrid1.Row < 0 Then Exit Sub

    cmd = " begin tran "
    cmd = cmd & " declare @x int, @name char(50)"
    cmd = cmd & " set nocount on "
    cmd = cmd & " SET @name='" & DataGrid1.Columns(0) & "' "
    cmd = cmd & " Exec @x=usp_Delete @name "
    cmd = cmd & " select @x X"
    cmd = cmd & " if @x=0 commit else rollback "

    Adodc1.RecordSource = cmd
    Adodc1.Refresh
    cc = Val(Adodc1.Recordset.Fields(0))
    If cc = 0 Then
       Adodc1.Refresh: DataGrid1.Refresh
       MsgBox "玩家信息删除成功!", , "提示": Exit Sub
    End If

P0: MsgBox "发生未知错误,调用失败!", vbOKOnly: Exit Sub
ErrorHandler: MsgBox (Err.Description & Chr(13) & Chr(10))
    Resume P0
End Sub
Private Sub Command2_Click()
    Unload Me
    aHome.Show vbModal
End Sub


搜索更多相关主题的帖子: SET name If cmd Sub 
2020-06-15 23:20
Littlewen
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2020-6-12
得分:0 
发现问题了
1.Player表中的pName(主键)是其他表的外键,要删除Player的记录要先删除其它表中pName对应的记录
2.用两个ADOC,一个用来显示datagrid 另一个接受cmd命名。
2020-06-16 14:06



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-502145-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.084765 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved