-----sql server 2008
USE [abc]
GO
/****** Object: StoredProcedure [dbo].[zero] Script Date: 07/26/2020 17:07:47 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: 杨宗会
-- Create date: 2020-07-26
-- Description: mdsn qq_457565758
---分母为零时的出错信息。
-- =============================================
ALTER PROCEDURE [dbo].[zero]
-- Add the parameters for the stored procedure here
@A int,
@b int,
@c int,
@msgError varchar(200) output
AS
BEGIN
SET NOCOUNT ON;
begin try
set @c=@a/@b
end try
begin catch
select @msgError=ERROR_MESSAGE();
raiserror(@msgError,16,1)
end catch
END
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
object Form1: TForm1
Left = 0
Top = 0
Caption = 'Form1'
ClientHeight = 201
ClientWidth = 447
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'Tahoma'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object AbcConnection: TFDConnection
Params.Strings = (
'ConnectionDef=ABC')
Connected = True
LoginPrompt = False
Left = 143
Top = 29
end
object ZeroProc: TFDStoredProc
Connection = AbcConnection
StoredProcName = 'abc.dbo.zero'
Left = 112
Top = 119
ParamData = <
item
Position = 1
Name = '@RETURN_VALUE'
DataType = ftInteger
ParamType = ptResult
end
item
Position = 2
Name = '@A'
DataType = ftInteger
ParamType = ptInput
end
item
Position = 3
Name = '@b'
DataType = ftInteger
ParamType = ptInput
end
item
Position = 4
Name = '@c'
DataType = ftInteger
ParamType = ptInput
end
item
Position = 5
Name = '@msgError'
DataType = ftString
ParamType = ptInputOutput
Size = 200
end>
end
end
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, FireDAC.Stan.Intf, FireDAC.Stan.Option,
FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf, FireDAC.Stan.Def,
FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys, FireDAC.Phys.MSSQL,
FireDAC.Phys.MSSQLDef, FireDAC.VCLUI.Wait, FireDAC.Stan.Param, FireDAC.DatS,
FireDAC.DApt.Intf, FireDAC.DApt, Data.DB, FireDAC.Comp.DataSet,
FireDAC.Comp.Client;
type
TForm1 = class(TForm)
AbcConnection: TFDConnection;
ZeroProc: TFDStoredProc;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
try
ZeroProc.ExecProc('Zero', [100, 0]);-----100/0
except
showmessage (ZeroProc.ParamByName('@msgError').Value);-----出错捕错
end;
end;
end.