简体   繁体   English

使用ODP.net更新表时出现错误ORA-01722

[英]Error ORA-01722 when updating a table using ODP.net

I'm trying update a table that looks something like: 我正在尝试更新看起来像这样的表:

column a VARCHAR2(80)

Using the following function: 使用以下功能:

sqlString = "UPDATE TABLE SET domicilio = :p_domicilio WHERE codigo = :p_codigo";
string sqlCommandtext = sqlString; 
using (var cn = new OracleConnection("DATA SOURCE=XXX..."))
{
    cn.Open();

    using (OracleCommand commandInt32 = cn.CreateCommand())
    {
        cmd.CommandText = sqlCommandtext;
        cmd.Parameters.Add("p_codigo", OracleDbType.Int32, 34620, ParameterDirection.Input);

        cmd.Parameters.Add("p_domicilio", OracleDbType.Varchar2, ParameterDirection.Input).Value = domicilio;
        //cmd.Parameters.Add("p_domicilio", OracleDbType.Varchar2, domicilio, ParameterDirection.Input);

        cmd.ExecuteNonQuery();
    }
}

but get " ORA-01722 invalid number " exception. 但会收到“ ORA-01722无效号码 ”异常。

I try 我尝试

cmd.Parameters.Add("p_domicilio", OracleDbType.Varchar2, ParameterDirection.Input).Value = domicilio;

and

cmd.Parameters.Add("p_domicilio", OracleDbType.Varchar2, domicilio, ParameterDirection.Input);

and

    var pDomicilio = new Oracle.DataAccess.Client.OracleParameter()
    {
        DbType = DbType.String,
        Value = domicilio,
        Direction = ParameterDirection.Input,
        OracleDbType = Oracle.DataAccess.Client.OracleDbType.Varchar2,
        ParameterName = "p_domicilio",
    };

By default, ODP.Net binds parameters by the Order they are provided, not by name, and you are specifying the second parameter codigo before the first parameter domicilio . 默认情况下,通过ODP.Net订单绑定参数向他们提供,而不是由名称,是否指定了第二个参数codigo第一个参数之前domicilio Bind by order means the name of the parameter is ignored. 按顺序绑定意味着将忽略参数名称。

Either change the command Binding to Name ( cmd.BindByName = true ), or provide the parameters in the same order that they are used in your command. 将命令Binding更改为Namecmd.BindByName = true ),或者以与命令中使用的顺序相同的顺序提供参数。

If this is a big project, I would suggest creating a factory plumbing method for returning OracleCommand s which will be set to BindByName 如果这是一个大项目,我建议创建一个工厂管道方法来返回OracleCommand ,该方法将设置为BindByName

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

相关问题 C#:使用存储过程和ODP.NET更新BLOB时出现错误ORA-06550 - C# : Getting error ORA-06550 while updating BLOB using stored procedure & ODP.NET 将Microsoft OracleClient迁移到ODP.NET时出现错误“ ORA-03135:连接失去联系”的原因是什么 - What the reason of error “ORA-03135: Connection lost contact” when migration Microsoft OracleClient to ODP.NET 与ODP.Net连接的ORA-01005错误 - ORA-01005 error connecting with ODP.Net ORA-01403:找不到数据ORA-06512:尝试使用ODP.NET运行存储的proc的第1行 - ORA-01403: no data found ORA-06512: at line 1 when trying to run a stored proc using ODP.NET 使用 OracleConnection.Open() 时出错 ORA-00303:网络库:名称-值语法错误 ODP.NET 托管 dll - Error when using OracleConnection.Open() ORA-00303: Network Library: Name-Value syntax error ODP.NET managed dll ORA-1461与托管ODP.Net - ORA-1461 with Managed ODP.Net 使用ODP.Net的问题 - Problem on using ODP.Net ORA-01017:使用ODP.NET,托管驱动程序连接到9i oracle数据库时,无效的用户名/密码 - ORA-01017: invalid username/password when connecting to 9i oracle database using the ODP.NET, Managed Driver 选择最近在ODP.NET中用ALTER TABLE插入的列时出错 - Error selecting column recently inserted with ALTER TABLE in ODP.NET ORA-01722:编号#2无效 - ORA-01722: invalid number #2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM