Illegal attempt to use Text/Byte host variable - Inserting into TEXT column

Deadly 提交于 2019-12-02 05:29:51

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.

I'm not sure I know what setup I would need to repro this... However, here's something to try:

It looks like Informix wants positional parameters. Recent builds of dapper actually support a modified syntax to make this more convenient. Can you try:

conn.Execute("INSERT INTO notepads (np_c_ref, np_type,np_text) VALUES (?np_c_ref?,?np_np_type?,?np_text?)",dynParams);

Also: try using 'T' instead of "T" (character versus string).

This might help if the issue is parameter order. Note also: if this works, you can possibly also use the more-convenient anonymous type approach to specify the parameters:

conn.Execute("INSERT INTO notepads (np_c_ref, np_type,np_text) VALUES (?np_c_ref?,?np_np_type?,?np_text?)",
new { np_c_ref = -1, np_np_type = "T",
    np_text = System.Text.Encoding.Default.GetBytes("TEXT INPUT")
});

Final final thought: there are virtually no scenarios in which Encoding.Default is either correct or appropriate. It is rarely used, except by mistake.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!