简体   繁体   English

将 null 值插入 DB2 中的 integer 列

[英]Inserting null value to integer column in DB2

I have tried it before in mysql DB and it is working fine but this time seems like the syntax is not applicable for DB2 and it giving me exception if the variable is empty:我之前在 mysql DB 中尝试过它,它工作正常,但这次语法似乎不适用于 DB2,如果变量为空,它会给我异常:

Here is my sample snippet:这是我的示例片段:

var num = "";
string insert_qry = "INSERT INTO myTable(myCol) VALUES (@num)";
DB2Command checkCommand = new DB2Command(insert_qry, myConnection);

checkCommand.Parameters.Add("@num ", num ?? null);
affectRowNum = checkCommand.ExecuteNonQuery();

If I assign value from the variable it works fine but it is empty it will return this exception error:如果我从变量赋值它工作正常但它是空的它将返回这个异常错误:

IBM.Data.DB2.Core.DB2Exception: 'External component has thrown an exception.'

Any suggestion/Comments TIA任何建议/意见 TIA

Try DbNull.Value this worked for me.试试DbNull.Value这对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM