参数化oracle命令c#
我在使用参数化 oracle 命令时遇到问题。该命令似乎可以识别所有字符串参数(:Id,:CreateUser),但不能识别字符参数(:Active)。
string qry = @"Insert into GROUP_LOGIN
(
GROUP_ID,
CREATED_ON,
ACTIVE_FLAG,
CREATED_USER
)
values
(
:Id,
SYSDATE,
:Active,
:CreateUser
)";
OracleCommand cmd = dal.GetOracleCommand();
if (cmd != null)
{
cmd.CommandText = qry;
OracleParameter op= new OracleParameter("Active",OracleDbType.Char);
op.Value = active;
//cmd.Parameters.Add(op);
OracleParameter[] myParams = new OracleParameter[]
{
new OracleParameter("Id", this.GrpID),
new OracleParameter("Description", this.Description),
new OracleParameter("CreateUser", this.Create_User),
new OracleParameter("Remarks", this.Remarks),
op
};
for (int i = 0; i < myParams.Length; i++)
{
cmd.Parameters.Add(myParams[i]);
}
//...
}
我尝试了不同的方法来执行此操作,但每次使用这两种类型的参数时, char 参数都不会被识别。当只考虑字符参数时,它可以正常工作,但否则会报错
ORA-01400: cannot insert NULL into ("User"."GROUP_LOGIN"."ACTIVE_FLAG")
I have a problem using parameterized oracle command. The command seem to recognise all the string parameters (:Id,:CreateUser) but not the character parameter(:Active).
string qry = @"Insert into GROUP_LOGIN
(
GROUP_ID,
CREATED_ON,
ACTIVE_FLAG,
CREATED_USER
)
values
(
:Id,
SYSDATE,
:Active,
:CreateUser
)";
OracleCommand cmd = dal.GetOracleCommand();
if (cmd != null)
{
cmd.CommandText = qry;
OracleParameter op= new OracleParameter("Active",OracleDbType.Char);
op.Value = active;
//cmd.Parameters.Add(op);
OracleParameter[] myParams = new OracleParameter[]
{
new OracleParameter("Id", this.GrpID),
new OracleParameter("Description", this.Description),
new OracleParameter("CreateUser", this.Create_User),
new OracleParameter("Remarks", this.Remarks),
op
};
for (int i = 0; i < myParams.Length; i++)
{
cmd.Parameters.Add(myParams[i]);
}
//...
}
I have tried different ways of doing this but everytime I use these two types of parameters the char parameter does not get recognised. When the character parameters is only considered, it works correctly but else it gives error
ORA-01400: cannot insert NULL into ("User"."GROUP_LOGIN"."ACTIVE_FLAG")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用
op.Value = active;
设置了(显然)空值,您是否确定active
确实具有某些值?根据此代码,它可能为 null,并且在这种情况下错误消息将有效。You set the (apparently) null value with
op.Value = active;
, have you made sure thatactive
truly has some value? Based on this code, it could be null and the error message would be valid in that case.