不支持指定的方法

时间:2016-10-26 05:30:26

标签: c# oracle

尝试从oracle数据库表中检索单个值,代码如下

public int _getProductPrice(string product_id)
    {
    Int16 price = 0;
       string query = string.Format(@"select sum(price) price from sales where product_id = '{0}'", product_id);
       string connectionString = String.Format("SERVER=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST={0})(PORT={1}))(CONNECT_DATA=(SERVICE_NAME={2})));uid={3};pwd={4};", AppConfig.OraDBHOST, AppConfig.OraDBPORT, AppConfig.OraDBNAME, AppConfig.OraDBUSER, AppConfig.OraDBPWD);
       using (OracleConnection connection = new OracleConnection(connectionString))
       {
           OracleCommand cm = new OracleCommand(query);
           try
           {
              cm.Connection = connection;
              connection.Open();
              OracleDataReader reader = cm.ExecuteReader();
              reader.Read();
              price = reader.GetInt16(0);
            }
            catch(Exception e) {
                throw new Exception(e.Message);
            }
        }
       return price;
       }

但是异常返回"指定的方法不受支持",不确定哪种方法。 我错了什么?

0 个答案:

没有答案