Delphi 使用TAdoQuery执行存储过程的样例

procedure TCustomerForm.FindCustomerInfo;
var
  strSql:string;
begin

 //  BL_HV_FindCustomerInfo 存储过程的名称,后面是需要的全部的参数
  strSql:='exec BL_HV_FindCustomerInfo :StyleInt,:CustomerName,:RelationName,'
         +':RelationPhone,:Address,:CustomerStatus,:ErrorCode output,:ErrorMessage output';


  with adoQryCustomer do
  begin
    Close;
    SQL.Clear;
    SQL.Add(strSql);
    if rbOr.Checked = True then
      Parameters.ParamByName('StyleInt').Value := '0'
    else
      Parameters.ParamByName('StyleInt').Value := '1';
    Parameters.ParamByName('CustomerName').Value := Trim(edtFindCustomerName.Text);
    Parameters.ParamByName('RelationName').Value := Trim(edtFindRelationName.Text);
    Parameters.ParamByName('RelationPhone').Value := Trim(edtFindRelationPhone.Text);
    Parameters.ParamByName('Address').Value := Trim(edtFindAddress.Text);
    if cbFindCustomerStatus.Checked then
    Parameters.ParamByName('CustomerStatus').Value :=1
    else
    Parameters.ParamByName('CustomerStatus').Value :=0;
    ExecSQL;
    ErrorCodeStr := Parameters.ParamByName('ErrorCode').Value;

    if ErrorCodeStr <> '0' then
      ShowMessage(Parameters.ParamByName('ErrorMessage').Value)
    else
      Active := True;
  end;
  if dbgrdhCustomer.CanFocus then
    dbgrdhCustomer.SetFocus;
end;

转自:https://blog.csdn.net/xiongmao000738/article/details/6956094

猜你喜欢

转载自www.cnblogs.com/railgunman/p/9549101.html