Click here to Skip to main content
16,005,734 members
Home / Discussions / Database
   

Database

 
GeneralRe: selecting from table rows including email address with @ sign Pin
Luis Alonso Ramos21-Nov-04 16:43
Luis Alonso Ramos21-Nov-04 16:43 
GeneralRe: selecting from table rows including email address with @ sign Pin
grossd21-Nov-04 17:45
grossd21-Nov-04 17:45 
GeneralRe: selecting from table rows including email address with @ sign Pin
Luis Alonso Ramos21-Nov-04 18:45
Luis Alonso Ramos21-Nov-04 18:45 
GeneralDataGrid Problem Pin
Mr.Cooper21-Nov-04 2:23
Mr.Cooper21-Nov-04 2:23 
Generalquery nullable colunn will always get null Pin
JabraJabra20-Nov-04 23:12
JabraJabra20-Nov-04 23:12 
GeneralRe: query nullable colunn will always get null Pin
Colin Angus Mackay21-Nov-04 1:51
Colin Angus Mackay21-Nov-04 1:51 
GeneralRe: query nullable colunn will always get null Pin
JabraJabra21-Nov-04 4:58
JabraJabra21-Nov-04 4:58 
GeneralGetting values of output parameters Pin
Luis Alonso Ramos20-Nov-04 6:49
Luis Alonso Ramos20-Nov-04 6:49 
Hello,

I'm having problems retrieving the values of a stored procedure's output parameters. I don't know if the problem is in the stored procedure or in the code.

When the procedure is executed, the records in the three tables are inserted correctly, and the identity from the first table is stored correctly in the other two tables.

When I try to get the value of the parameter after the ExecuteNonQuery call, an InvalidCastException exception is thrown. This is my code:
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Transaction = trans;

cmd.CommandText = "ReprDist_InsertDistributor";
cmd.Parameters.Add("@ID_representante", data.RepID);

cmd.Parameters.Add("@NombreComercial",  (string) row["NombreComercial"]);
// ... many more parameters!
cmd.Parameters.Add("@Password",         (string) row["Password"]);

SqlParameter paramDistID = cmd.Parameters.Add("@ID_distribuidor", SqlDbType.Int);
paramDistID.Direction = ParameterDirection.Output;
SqlParameter paramCompID = cmd.Parameters.Add("@ID_empresa", SqlDbType.Int);
paramCompID.Direction = ParameterDirection.Output;
SqlParameter paramUserID = cmd.Parameters.Add("@ID_usuario", SqlDbType.Int);
paramUserID.Direction = ParameterDirection.Output;

cmd.ExecuteNonQuery();

data.DistID    = (int) paramDistID.Value;
data.CompanyID = (int) paramCompID.Value;
data.UserID    = (int) paramUserID.Value;
and this is my stored procedure:
ALTER PROCEDURE ReprDist_InsertDistributor
(
    @ID_representante int,

    @NombreComercial varchar(70),
/* many more input parameters */
    @Password varchar(20),

    @ID_distribuidor int OUTPUT,
    @ID_empresa int OUTPUT,
    @ID_usuario int OUTPUT
)
AS

INSERT INTO Empresas (NombreComercial, Direccion, Ciudad, Estado, Telefono, DireccionWeb, EMail, RazonSocial, DireccionFiscal, RFC)
    VALUES (@NombreComercial, @Direccion, @Ciudad, @Estado, @Telefono, @DireccionWeb, @EMail, @RazonSocial, @DireccionFiscal, @RFC);
SELECT @ID_empresa = @@IDENTITY;

INSERT INTO Distribuidores (ID_empresa, ID_representante) VALUES (@ID_empresa, @ID_representante);
SELECT @ID_distribuidor = @@IDENTITY;

INSERT INTO Usuarios (Nombre, Apellido, Telefono, EMail, NombreUsuario, Password, ID_empresa)
    VALUES (@Nombre, @Apellido, @TelefonoContacto, @EMailContacto, @NombreUsuario, @Password, @ID_empresa);
SELECT @ID_usuario = @@IDENTITY;

RETURN;
If anyone can help me out, I'd appreciate it very much!

Thanks!

-- LuisR



Luis Alonso Ramos
Intelectix - Chihuahua, Mexico

Not much here: My CP Blog!

GeneralRe: Getting values of output parameters Pin
Luis Alonso Ramos20-Nov-04 21:54
Luis Alonso Ramos20-Nov-04 21:54 
GeneralRe: Getting values of output parameters Pin
Colin Angus Mackay21-Nov-04 1:53
Colin Angus Mackay21-Nov-04 1:53 
GeneralODBC Error Pin
Member 64506720-Nov-04 0:08
Member 64506720-Nov-04 0:08 
GeneralConditional Where Clause in MS SQL SProc Pin
anotheruser19-Nov-04 4:17
anotheruser19-Nov-04 4:17 
GeneralRe: Conditional Where Clause in MS SQL SProc Pin
Colin Angus Mackay20-Nov-04 5:33
Colin Angus Mackay20-Nov-04 5:33 
GeneralRe: Conditional Where Clause in MS SQL SProc Pin
anotheruser20-Nov-04 12:20
anotheruser20-Nov-04 12:20 
GeneralRe: Conditional Where Clause in MS SQL SProc Pin
.#Dev21-Nov-04 4:14
.#Dev21-Nov-04 4:14 
GeneralRe: Conditional Where Clause in MS SQL SProc Pin
Colin Angus Mackay21-Nov-04 4:45
Colin Angus Mackay21-Nov-04 4:45 
GeneralRe: Conditional Where Clause in MS SQL SProc Pin
anotheruser21-Nov-04 4:53
anotheruser21-Nov-04 4:53 
GeneralRe: Conditional Where Clause in MS SQL SProc Pin
.#Dev21-Nov-04 4:46
.#Dev21-Nov-04 4:46 
Generalcannot take .dbf files via DTS Pin
steven_wong18-Nov-04 21:18
steven_wong18-Nov-04 21:18 
GeneralNo data found, but HasRows Pin
Vector718-Nov-04 6:14
Vector718-Nov-04 6:14 
GeneralRe: No data found, but HasRows Pin
lokin118-Nov-04 6:49
lokin118-Nov-04 6:49 
GeneralEvaluating decimal type Pin
totig18-Nov-04 1:11
totig18-Nov-04 1:11 
GeneralRe: Evaluating decimal type Pin
Colin Angus Mackay18-Nov-04 1:37
Colin Angus Mackay18-Nov-04 1:37 
GeneralParadox Binary Blob Pin
elapid18-Nov-04 0:53
elapid18-Nov-04 0:53 
GeneralUpdate Pin
vuthaianh17-Nov-04 16:56
vuthaianh17-Nov-04 16:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.