delphi怎么调用sql存储过程
var
ADOConnection1: TADOConnection;
ADOStoredProc1: TADOStoredProc;
begin
ADOConnection1 := TADOConnection.Create(nil);
ADOStoredProc1 := TADOStoredProc.Create(nil);
try
// 设置数据库连接属性
ADOConnection1.ConnectionString := 'Provider=SQLOLEDB;Data Source=YourServerName;Initial Catalog
=YourDatabaseName;User ID=YourUserID;Password=YourPassword';
ADOConnection1.LoginPrompt := False;
ADOConnection1.Connected := True;
// 设置 TADOStoredProc 组件的属性
ADOStoredProc1.Connection := ADOConnection1;
ADOStoredProc1.ProcedureName := 'YourStoredProcedureName';
ADOStoredProc1.Parameters.Refresh; // 刷新参数列表
// 设置存储过程的输入参数值
ADOStoredProc1.Parameters.ParamByName('ParamName1').Value := ParamValue1;
ADOStoredProc1.Parameters.ParamByName('ParamName2').Value := ParamValue2;
// 执行存储过程
ADOStoredProc1.ExecProc;
// 检查存储过程的返回值或输出参数的值
ReturnValue := ADOStoredProc1.Parameters.ParamByName('ReturnValue').Value;
OutputParamValue := ADOStoredProc1.Parameters.ParamByName('OutputParamName').Value;
finally
ADOStoredProc1.Free;
ADOConnection1.Free;
end;
end;