非法尝试使用Text/Byte主机变量-插入TEXT列 [英] Illegal attempt to use Text/Byte host variable - Inserting into TEXT column
问题描述
尝试通过Dapper插入表(文本列"),并从Informix获取错误:
Trying to insert into a table (Text Column) via Dapper, and getting the error from Informix:
Illegal attempt to use Text/Byte host variable
我已经编写了一个小程序来对此进行模拟,但是我仍然遇到问题.
I have written a small program to simulate this, and I am still up against problems.
我们当前无法使用Informix驱动程序,因为它们不符合我们的需求.
We cannot currently use the Informix drivers, as they do not suit our needs.
using Dapper;
using System;
using System.Data.Odbc;
namespace DapperParamsTest
{
class Program
{
static void Main(string[] args)
{
OdbcConnection conn = new System.Data.Odbc.OdbcConnection("Driver={IBM INFORMIX ODBC DRIVER (64-bit)}; Host=bylgia; Server=bylgia; Service=sqlexec; Protocol=onsoctcp; Database=DATABASE; Client_Locale=en_US.CP1252; DB_LOCALE=en_GB.1252");
var dynParams = new DynamicParameters();
dynParams.Add("np_c_ref",-1);
dynParams.Add("np_np_type","T");
dynParams.Add("np_text", System.Text.Encoding.Default.GetBytes("TEXT INPUT"), System.Data.DbType.Binary);
conn.Execute("INSERT INTO notepads (np_c_ref, np_type,np_text) VALUES (?,?,?)",dynParams);
Console.WriteLine("Written");
Console.ReadLine();
}
}
}
表结构:
CREATE TABLE notepad
(
np_c_ref int,
np_type char(1),
np_text TEXT
)
推荐答案
实际上,这个问题可能比我的其他答案要简单得多.我刚刚注意到您说该列为TEXT
,但您正在向其传递byte[]
.如果需要,您可能应该使用BYTE
数据类型.如果您想使用TEXT
-只需将string
(即"TEXT INPUT"
)传递给它,而忘记Encoding
.
This question might actually be a lot simpler than my other answer presumes; I've just noticed you say the column is TEXT
, yet you are passing it a byte[]
. If you want that, you should probably be using the BYTE
data type. If you want to use TEXT
- just pass it the string
(i.e. "TEXT INPUT"
) and forget about Encoding
.
这篇关于非法尝试使用Text/Byte主机变量-插入TEXT列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!