Implicit conversion from data type sql_variant to varchar is not allowed
Posted: Thu 21 May 2015 08:32
I'm working with SQL server.
If I try to do an INSERT like this:
TUniSQL *UniSQL = new TUniSQL(NULL);
UniSQL->Connection = UniConnection1;
UniSQL->Debug = true;
UniSQL->ParamCheck = false;
AnsiString text = "INSERT INTO AgeCategories VALUES (:AgeCategoryId, :AgeCategoryName, :LocalizedAgeCategoryName)";
UniSQL->SQL->Clear();
UniSQL->SQL->Add(text);
UniSQL->ParamCheck = true;
UniSQL->Prepared = true;
UniSQL->Params->ParamByName("AgeCategoryId")->AsString = "AA";
UniSQL->Params->ParamByName("AgeCategoryName")->AsString = "TEST";
UniSQL->Params->ParamByName("LocalizedAgeCategoryName")->AsString = AnsiString("a");
UniConnection1->StartTransaction();
try
{
UniSQL->Execute();
UniConnection1->Commit();
}
catch (Exception *E)
{
UniConnection1->Rollback();
throw E;
}
I get an exeption:
Project TestSQLServer.exe raised exception class EUniError with message 'Statement(s) could not be prepared.
Implicit conversion from data type sql_variant to varchar is not allowed. Use the CONVERT function to run this query.'. Process stopped. Use Step or Run to continue.
The table schema is the following:
CREATE TABLE [dbo].[AgeCategories](
[AgeCategoryId] [varchar](2) NOT NULL,
[AgeCategoryName] [nvarchar](50) NOT NULL,
[LocalizedAgeCategoryName] [nvarchar](50) NULL,
CONSTRAINT [PK_AgeCategories] PRIMARY KEY CLUSTERED
(
[AgeCategoryId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
It works if I execute visually on the form.
Regards
If I try to do an INSERT like this:
TUniSQL *UniSQL = new TUniSQL(NULL);
UniSQL->Connection = UniConnection1;
UniSQL->Debug = true;
UniSQL->ParamCheck = false;
AnsiString text = "INSERT INTO AgeCategories VALUES (:AgeCategoryId, :AgeCategoryName, :LocalizedAgeCategoryName)";
UniSQL->SQL->Clear();
UniSQL->SQL->Add(text);
UniSQL->ParamCheck = true;
UniSQL->Prepared = true;
UniSQL->Params->ParamByName("AgeCategoryId")->AsString = "AA";
UniSQL->Params->ParamByName("AgeCategoryName")->AsString = "TEST";
UniSQL->Params->ParamByName("LocalizedAgeCategoryName")->AsString = AnsiString("a");
UniConnection1->StartTransaction();
try
{
UniSQL->Execute();
UniConnection1->Commit();
}
catch (Exception *E)
{
UniConnection1->Rollback();
throw E;
}
I get an exeption:
Project TestSQLServer.exe raised exception class EUniError with message 'Statement(s) could not be prepared.
Implicit conversion from data type sql_variant to varchar is not allowed. Use the CONVERT function to run this query.'. Process stopped. Use Step or Run to continue.
The table schema is the following:
CREATE TABLE [dbo].[AgeCategories](
[AgeCategoryId] [varchar](2) NOT NULL,
[AgeCategoryName] [nvarchar](50) NOT NULL,
[LocalizedAgeCategoryName] [nvarchar](50) NULL,
CONSTRAINT [PK_AgeCategories] PRIMARY KEY CLUSTERED
(
[AgeCategoryId] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
It works if I execute visually on the form.
Regards