sql-server – 使用Delphi中的ADOConnection查看’print’语句的
发布时间:2020-12-12 08:29:41 所属栏目:MsSql教程 来源:网络整理
导读:我的一些MS SQL存储过程使用’print’命令产生消息.在我使用TADOConnection连接到MS SQL的Delphi 2007应用程序中,如何查看这些“打
我的一些MS SQL存储过程使用’print’命令产生消息.在我使用TADOConnection连接到MS SQL的Delphi 2007应用程序中,如何查看这些“打印”命令的输出?
主要要求: 解决方法那是一个有趣的…来自ADOConnection的OnInfoMessage事件起作用,但恶魔在细节中! 要点: SQL边:你的存储过程 SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[FG_TEST]') AND type in (N'P',N'PC')) DROP PROCEDURE [dbo].[FG_TEST] GO -- ============================================= -- Author: Fran?ois -- Description: test multi ADO with info -- ============================================= CREATE PROCEDURE FG_TEST AS BEGIN -- SET NOCOUNT ON absolutely NEEDED SET NOCOUNT ON; PRINT '*** start ***' SELECT 'one' as Set1Field1 PRINT '*** done once ***' SELECT 'two' as Set2Field2 PRINT '*** done again ***' SELECT 'three' as Set3Field3 PRINT '***finish ***' END GO 德尔福方面: 复制以下文本,更改目录和数据源并将其粘贴到表单上 object ADOConnection1: TADOConnection ConnectionString = 'Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security In' + 'fo=False;Initial Catalog=xxxYOURxxxDBxxx;Data Source=xxxYOURxxxSERVERxxx' CursorLocation = clUseServer LoginPrompt = False Provider = 'SQLOLEDB.1' OnInfoMessage = ADOConnection1InfoMessage Left = 24 Top = 216 end object ADOStoredProc1: TADOStoredProc Connection = ADOConnection1 CursorLocation = clUseServer ProcedureName = 'FG_TEST;1' Parameters = <> Left = 24 Top = 264 end 在OnInfoMessage中的ADOConnection put Memo1.Lines.Add(Error.Description); 对于ButtonClick,粘贴此代码 procedure TForm1.Button1Click(Sender: TObject); const adStateOpen = $00000001; // or defined in ADOInt var I: Integer; ARecordSet: _Recordset; begin Memo1.Lines.Add('=========================='); ADOStoredProc1.Open; // not ExecProc !!!!! ARecordSet := ADOStoredProc1.Recordset; while Assigned(ARecordSet) do begin // do whatever with current RecordSet while not ADOStoredProc1.Eof do begin Memo1.Lines.Add(ADOStoredProc1.Fields[0].FieldName + ': ' + ADOStoredProc1.Fields[0].Value); ADOStoredProc1.Next; end; // switch to subsequent RecordSet if any ARecordSet := ADOStoredProc1.NextRecordset(I); if Assigned(ARecordSet) and ((ARecordSet.State and adStateOpen) <> 0) then ADOStoredProc1.Recordset := ARecordSet else Break; end; ADOStoredProc1.Close; end; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容