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.
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();
}
}
}
Table Structure:
CREATE TABLE notepad
(
np_c_ref int,
np_type char(1),
np_text TEXT
)
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
.
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句