procedure TForm1.Button1Click(Sender: TObject); var v: variant; begin { [ODBC] DRIVER=SQL Server 会报错 DRIVER=ODBC Driver 18 for SQL Server 没问题 } dbProp := TSqlDBOdbcConnectionProperties.Create('', 'FILEDSN=d:\test.dsn;PWD=Sa12345', '', ''); // var stmt := dbProp.NewThreadSafeStatementPrepared('{? = call p_test (?,?) }', true, false); 第一个参数是返回值。 var stmt := dbProp.NewThreadSafeStatementPrepared('exec p_test ?,?', true, false); //无返回值 stmt.BindTextU(1, 'jjw', paramIn); stmt.Bind(2, 9, paramOut); stmt.ExecutePrepared; stmt.ParamToVariant(2, v); Caption := V; end;
ALTER proc [dbo].[p_test] @name varchar(10), @insId bigint output as begin SET NOCOUNT ON --关键 insert into test(name) values(@name) select @insId = @@IDENTITY return 0 end GO