简体   繁体   中英

OracleParameter to Int32 issue

I have a SQL code as follows:

public void UpdateDatabase(String strParam1, int row)
        {
            System.Data.OracleClient.OracleConnection conn = new System.Data.OracleClient.OracleConnection();
            conn.ConnectionString = "Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.5.144)(PORT = 1521))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = orcl)));UID=mwm;PWD=mwm"; 
                conn.Open();
                OracleCommand command = conn.CreateCommand();                       
               command.CommandText = "Select id from Task";
                OracleParameter taskId = new OracleParameter();
                taskId.DbType = DbType.Int32;                        
                taskId.Value = taskId;
                taskId.ParameterName = "taskId";
                command.Parameters.Add(taskId);
                command.ExecuteNonQuery();
                command.Dispose();
            }
        }

When ExecuteNonQuery is reached, I get an error "Failed to convert parameter value from a OracleParameter to a Int32" What is wrong here? I googled but couldn't come to a conclusion.

In this taskId.Value = taskId; you are assigning taskId which is of OracleParameter type a value taskID , its is expecting an int value. In other words you are assigning the same thing to its value parameter. Since you have defined: taskId.DbType = DbType.Int32; it is expecting an int value, and probably you miss typed it to assign taskId again.

添加调整您的查询

"Select id from Task where id = taskId";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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