RE:VB y Funciones de Postgres
Publicado por
Luis Matta (1 intervención) el 03/01/2008 19:56:49
Gracias Charli me sirvio de mucho tu codigo.
Pero, me gustaria pasarle los parametros uno por uno, ademas de recibir una respuesta. algun mensaje de error ya que mi command esta dentro de una funcion asi:
' FUNCION EN POSTGRES
CREATE OR REPLACE FUNCTION ft_insert_cliente (xsts_id varchar,xcli_dni varchar,xcli_fecnac timestamp,xcli_edad integer,xstcivil_id varchar, xcli_noms varchar,xcli_dir varchar,xcli_tel varchar,xcli_cel varchar,xcli_prof varchar, xdst_id varchar,xcli_email varchar,xcli_prom varchar) RETURNS varchar as
$BODY$
DECLARE
msg character varying;
begin
if $1 isnull then
msg := 'INGRESE EL TIPO O STATUS.';
return msg;
end if;
if $2 isnull then
msg := 'INGRESE DNI.';
return msg;
end if;
if $4 isnull then
msg := 'INGRESE LA EDAD.';
return msg;
end if;
if $5 isnull then
msg := 'SELECCIONE EL ESTADO CIVIL.';
return msg;
end if;
if $6 isnull then
msg := 'INGRESE EL NOMBRE.';
return msg;
end if;
if $7 isnull then
msg := 'INGRESE LA DIRECCION';
return msg;
end if;
if $10 isnull then
msg := 'INGRESE LA PROFESION.';
return msg;
end if;
if $11 isnull then
msg := 'SELECCIONE EL DISTRITO.';
return msg;
end if;
INSERT INTO CLIENTE (cli_id,sts_id,cli_dni,cli_fecnac,cli_edad,stcivil_id,cli_noms,cli_dir,cli_tel,cli_cel,cli_prof, dst_id,cli_email, cli_prom,log_fecreg,log_loginreg)
VALUES (1,xsts_id,xcli_dni,xcli_fecnac,xcli_edad,xstcivil_id, xcli_noms,xcli_dir,xcli_tel,xcli_cel,xcli_prof, xdst_id,xcli_email, xcli_prom,now(),current_user);
return '';
end;
$BODY$
language 'plpgsql';
' FUNCION EN VISUAL BASIC
' aqui faltan mas parametros pero los acorte por espacio.
Public Function Registra_Cliente( Xsts_id As String, Xcli_dni As String) As Boolean
Dim Ins As New Parameter
On Error GoTo Err_tranx
Set Cmd = Nothing
Cmd.ActiveConnection = DllCnx.Con
Cmd.CommandText = "select ft_insert_cliente"
Cmd.CommandType = adCmdText
Set Ins = Cmd.CreateParameter("xsts_id", adChar, adParamInput, 1)
Cmd.Parameters.Append Ins
Set Ins = Cmd.CreateParameter("xcli_dni", adChar, adParamInput, 8)
Cmd.Parameters.Append Ins
Set Ins = Cmd.CreateParameter("Error", adVarChar, adParamOutput, 100)
Cmd.Parameters.Append Ins
'ASIGNANDO EL VALOR AL PARAMETRO
Cmd.Parameters("xsts_id").Value = Xsts_id
Cmd.Parameters("xcli_dni").Value = Xcli_dni
'EJECUTA EL STORE PROC
Cmd.Execute
'VERIFICANDO SI HAY ERROR Y AVISAR AL USUARIO
If Cmd.Parameters("Error").Value <> "" Then
MsgBox Cmd.Parameters("Error").Value, vbCritical, "Clientes :: registrando ..."
Registra_Cliente = False
Exit Function
Else
Registra_Cliente = True
End If
Exit Function
ExitHere:
Registra_Cliente = False
Exit Function
Err_tranx:
Select Case VBA.Err.Number
Case Else
MsgBox "Error : " & VBA.Err.Description, 16, "Error en transacción"
End Select
Registra_Cliente = False
Resume ExitHere
End Function
' MI LLAMADO ES EL SIGUIENTE:
Dim Err As Boolean
DllCnx.Con.BeginTrans
Err = Registra_Cliente(DataStatus.BoundText, TxtDni.Text)
If Err = False Then
DllCnx.Con.RollbackTrans
Else
DllCnx.Con.CommitTrans
MsgBox "Los DATOS del cliente fueron registrados.", vbInformation, "Cliente"
End If
PERO ME SALE EL ERROR :
column "ft_insert_cliente" does not exist at character 8
POR FAVOR ESPERO ME PUEDAN AYUADAR
Luis Matta