Implicit conversion from data type sql_variant to int error

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Tugrul Tamturk
Posts: 32
Joined: Mon 25 Aug 2008 18:28

Implicit conversion from data type sql_variant to int error

Post by Tugrul Tamturk » Tue 07 Dec 2010 03:17

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

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Tue 07 Dec 2010 10:17

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.

Tugrul Tamturk
Posts: 32
Joined: Mon 25 Aug 2008 18:28

Post by Tugrul Tamturk » Tue 07 Dec 2010 10:49

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

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Tue 07 Dec 2010 12:13

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;

Tugrul Tamturk
Posts: 32
Joined: Mon 25 Aug 2008 18:28

More flexible solution

Post by Tugrul Tamturk » Tue 07 Dec 2010 13:28

Thanks... The solution accepted.

Regards
Tugrul

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Tue 07 Dec 2010 13:47

Hello,

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

Post Reply