方法 'Equals' 没有重载采用“0”参数
No overload for method 'Equals' takes '0' arguments
我正在尝试修复我在第 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;
}
}
Equals() 在这种情况下没有多大意义。你想做什么?将这些结果转换为 int,对吗?
所以不用
aliq.ALIQUOT_ID =reader["ALIQUOT_ID"].Equals();
使用
aliq.ALIQUOT_ID =Convert.ToInt32(reader["ALIQUOT_ID"]);
只需删除每行末尾的 .Equals()
。假设您的 table 中的每个字段都是一个整数,那么 reader[<fieldname>]
将为您提供相关值。
MSDN 说到 OracleDataReader 列索引器:
Gets the value of the specified column in its native format given the
column name.
因此,您应该能够从这些行中删除 .Equals()。
如果还是不行,试试:
Convert.ToInt32(reader["ALIQUOT_ID"])
希望对您有所帮助
我正在尝试修复我在第 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;
}
}
Equals() 在这种情况下没有多大意义。你想做什么?将这些结果转换为 int,对吗?
所以不用
aliq.ALIQUOT_ID =reader["ALIQUOT_ID"].Equals();
使用
aliq.ALIQUOT_ID =Convert.ToInt32(reader["ALIQUOT_ID"]);
只需删除每行末尾的 .Equals()
。假设您的 table 中的每个字段都是一个整数,那么 reader[<fieldname>]
将为您提供相关值。
MSDN 说到 OracleDataReader 列索引器:
Gets the value of the specified column in its native format given the column name.
因此,您应该能够从这些行中删除 .Equals()。
如果还是不行,试试:
Convert.ToInt32(reader["ALIQUOT_ID"])
希望对您有所帮助