ScriptManager中的警报脚本无法处理来自存储过程

时间:2016-05-04 16:57:40

标签: javascript asp.net sql-server vb.net

我编写了一个存储过程,如果某些条件失败,则使用RAISERROR返回错误消息。有时多个条件失败,多个RAISERROR消息将出现,并且在代码中我想要提醒这些消息。对于单个消息ScriptManager工作没有任何问题但是对于多个RAISERROR它没有工作,并且mozilla中的firebug显示错误“未终止的字符串文字”。我如何解决这个问题?

ALTER PROCEDURE [dbo].[proc1] @RequestId BIGINT

AS
BEGIN
  SET NOCOUNT ON;

  BEGIN TRAN

  IF @RequestId < 0
    BEGIN
        RAISERROR('MESSAGE1',16,1)
    END

  SET @RequestId = @RequestId + 100

  IF @RequestId < 0
    BEGIN
        RAISERROR('MESSAGE2',16,1)
    END

 UPDATE Table1 SET ID = @RequestId 

 SELECT @RequestId AS ID

  COMMIT TRAN
END 

在vb代码中

        Using con As New SqlConnection(ConfigurationManager.ConnectionStrings("ConStrMain").ConnectionString)
            con.Open()
            Using transaction As SqlTransaction = con.BeginTransaction
                Using cmd As New SqlCommand("proc1", con, transaction)
                    cmd.CommandType = CommandType.StoredProcedure
                    cmd.Parameters.AddWithValue("@RequestId", RequestId)
                    Try
                        cmd.ExecuteNonQuery()
                        transaction.Commit()
                        ScriptManager.RegisterClientScriptBlock(Page, GetType(System.Web.UI.Page), "", "alert('Request Successfully Completed');", True)
                    Catch ex As Exception
                        transaction.Rollback()
                        ScriptManager.RegisterClientScriptBlock(Page, GetType(System.Web.UI.Page), "", "alert('"+ex.Message+"');", True)
                    End Try
                End Using
            End Using
        End Using

0 个答案:

没有答案