Page 1 of 1

Implicit conversion from data type sql_variant to int error

Posted: Tue 07 Dec 2010 03:17
by Tugrul Tamturk
Hi,

I try to execute stored procedure with output parameter.

var UniCommand : TUniSql;
begin
UniCommand.ParamCheck := True
UniCommand.SQL.Text := 'EXEC A_STOREDPROC_NAME 0,:IPAR OUTPUT';
for i := 0 to UniCommand.Params.Count-1 do
UniCommand.Params.ParamType := ptInputOutput; // Direction := pdOutput;
UniCommand.Prepare;
UniCommand.Execute;
end;

I get "Implicit conversion from data type sql_variant to int is not allowed. Use CONVERT function to run this query".

I did not get this error if I use AdoCommand.

How to solve this problem.

Thanks
Tugrul

Posted: Tue 07 Dec 2010 10:17
by AlexP
Hello,

Please specify the following information so that I could reproduce the problem:
- the exact version of UniDAC;
- the exact version of your IDE;
- the exact version of SQL server;
- the script to create a stored procedure.

Posted: Tue 07 Dec 2010 10:49
by Tugrul Tamturk
Hi,

Unidac 3.00.0.10 for Delphi 7

MsSQL 2005 Standart Edition

Sample stored procedure is.. ( you can adapt to your test environment )

CREATE PROCEDURE [dbo].[A_STOREDPROC_NAME](@ID INT,@NEWID INT OUTPUT) AS
begin
INSERT INTO ATABLE (AFIELD) VALUES (0)
SET @NEWID = SCOPE_IDENTITY()
end;

Regards
Tugrul

Posted: Tue 07 Dec 2010 12:13
by AlexP
Hello,

To resolve the problem you should set the correct data type to the param like

for i := 0 to UniCommand.Params.Count-1 do
begin
UniCommand.Params.DataType:= ftInteger; <-set the data type
UniCommand.Params.ParamType := ptInputOutput; // Direction := pdOutput;
end;

More flexible solution

Posted: Tue 07 Dec 2010 13:28
by Tugrul Tamturk
Thanks... The solution accepted.

Regards
Tugrul

Posted: Tue 07 Dec 2010 13:47
by AlexP
Hello,

It is good to see that this problem was solved. If any other questions come up, please contact us.