Switching from ADO to SDAC, and getting sql_variant to varchar conversion error

Discussion of open issues, suggestions and bugs regarding SDAC (SQL Server Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
MRCarver
Posts: 2
Joined: Wed 17 Jan 2007 20:45

Switching from ADO to SDAC, and getting sql_variant to varchar conversion error

Post by MRCarver » Wed 17 Jan 2007 20:56

We just purchased SDAC and immediately got this message. This error does not get raised with ADO.

This was not a query but an update statement. What is the solution to fixing this problem? The field "ACTOR_MEMCISID" is a varchar(13).

ERROR MESSAGE :

An exception was raised on the server: Statement(s) could not be prepared.
Disallowed implicit conversion from data type sql_variant to data type varchar, table 'NUAVS.dbo.TBL_LDAP_CURRENT', column 'ACTOR_MEMCISID'. Use the CONVERT function to run this query.

Jackson
Posts: 512
Joined: Thu 26 Jan 2006 10:06

Post by Jackson » Thu 18 Jan 2007 11:25

You have to specify the parameters information before calling the TMemDataSet.Prepare method.
For example:

Code: Select all

 MSQuery1.SQL.Text := 'update TestTable set c_varchar = :p1 where ID = :p2';
 MSQuery1.ParamByName('p1').ParamType := ptInput;
 MSQuery1.ParamByName('p1').DataType := ftString;
 MSQuery1.ParamByName('p2').ParamType := ptInput;
 MSQuery1.ParamByName('p2').DataType := ftInteger;
 MSQuery1.Prepare;

 MSQuery1.ParamByName('p1').Value := '123456789';
 MSQuery1.ParamByName('p2').Value := 1;
 MSQuery1.Execute;

Post Reply