方法'Equals'没有重载需要'0'参数

时间:2015-03-23 14:35:57

标签: c# datareader

我正在尝试修复第34行和第35行下面的代码中出现的错误。

aliq.ALIQUOT_ID = reader["ALIQUOT_ID"].Equals();
aliq.SAMPLE_ID = reader["SAMPLE_ID"].Equals(); 

Aliquot_ID和Sample_ID都是整数。但是,我写这些线的方式 我收到以下错误:

Error   1   No overload for method 'Equals' takes '0' arguments C:...App_Code\DAL\DAL.cs    34. 
Error   2   No overload for method 'Equals' takes '0' arguments C:...App_Code\DAL\DAL.cs    35.

我应该如何写这两行来解决这个问题。

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Oracle.DataAccess.Client;


namespace Data
{
/// <summary>
/// Summary description for DAL
/// </summary>
public class DAL
{
    public static Model.Aliquot GetAliquot_ID(int aliqID)
    {
        string cs =         ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
        OracleConnection conn = null;
        OracleDataReader reader = null;
        try
        {
            conn = new OracleConnection(cs);
            string oracle = "SELECT SAMPLE_ID, ALIQUOT_ID, MATRIX_TYPE FROM LIMS.ALIQUOT WHERE ALIQUOT_ID = '" + aliqID + "'";
            OracleCommand cmd = new OracleCommand(oracle, conn);
            conn.Open();
            reader = cmd.ExecuteReader();
            reader.Read();
            Model.Aliquot aliq = new Model.Aliquot();
            aliq.ALIQUOT_ID = reader["ALIQUOT_ID"].Equals();
            aliq.SAMPLE_ID = reader["SAMPLE_ID"].Equals();
            aliq.MATRIX_TYPE = reader["MATRIX_TYPE"].ToString();
            return aliq;
        }
        catch (Exception exp)
        {
            //Add Logging
            HttpContext.Current.Trace.Warn("Error", "Error in GetAliquot_ID()", exp);
        }
        finally
        {
            if (reader != null) reader.Close();
            if (conn != null && conn.State != ConnectionState.Closed) conn.Close();
        }
        return null;
    }
}

3 个答案:

答案 0 :(得分:3)

Equals()在这种情况下没有多大意义。你想做什么?将这些结果转换为int,对吗?

所以而不是

aliq.ALIQUOT_ID =reader["ALIQUOT_ID"].Equals();

使用

aliq.ALIQUOT_ID =Convert.ToInt32(reader["ALIQUOT_ID"]);    

答案 1 :(得分:1)

只需从每行末尾删除.Equals()即可。假设表中的每个字段都是一个整数,那么reader[<fieldname>]将为您提供相关的值。

答案 2 :(得分:1)

MSDN说明了OracleDataReader列索引器:

  

在给定的情况下以其本机格式获取指定列的值   列名。

因此,您应该能够从这些行中删除.Equals()。

如果不起作用,请尝试:

Convert.ToInt32(reader["ALIQUOT_ID"])

希望有所帮助

相关问题