即使存在要显示的值,行中的DataColumn也会导致错误

问题描述 投票:0回答:2

我创建了一个非常简单的类,称为adjustment,然后在DataSet中填充4个表以从中选择数据。由于某些原因,当我尝试设置AccountNumber属性时,代码会炸毁(没有特定的错误)。我已经验证了我的表和列是否在DataSet中,甚至还进一步确认了一个值和长度与数据库中的值匹配。对于可能出现的问题,我有点不知所措。

我的对象:

public class Adjustment
{
    public string AccountNumber
    {
        get { return AccountNumber; }
        set { AccountNumber= value; }
    }     
}

我的用于填充数据集的代码:

    using (SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["dbc"]))
    {
        SqlCommand sqlComm = new SqlCommand("Adjustment_EXRACT", conn);
        sqlComm.Parameters.AddWithValue("@Account_ID", Account_ID);

        sqlComm.CommandType = CommandType.StoredProcedure;

        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = sqlComm;

        da.Fill(ds);

        List<Adjustment> accountAdjustment= new List<Adjustment>();
        accountAdjustment.Add(GetAccountAdjustment(ds));

    }

[GetAccountAdjustment方法:

       public Adjustment GetAccountAdjustment(DataSet ds)
        {
        Adjustment accAdj= new Adjustment();
        try
        {
            DataSet acEdits = ds;

            foreach (DataRow row in ds.Tables[0].Rows)
            {


                clinicalEdit.accountNumber= row["accountNumber"].ToString();

            }
        }
        catch (Exception ex)
        {
            LogUtil.Debug(ex.InnerException.ToString());
        }

        if (accAdj.accountNumber!= null)
            return (accAdj);
        else
            return null;
    }
}
c# sql asp.net ado
2个回答
0
投票

您是否看到您的调整类具有奇怪的获取/设置...?也许应该是

public class Adjustment
{
    private string _accountNumber;
    public string AccountNumber
    {
        get { return _accountNumber; }
        set { _accountNumber = value; }
    }     
}

属性和字段不同。


0
投票

您有错字。调整具有成员AccountNumber(大写字母),但您在GetAccountAdjustment中引用accountNumber(小写的起始字母)。

而且,在GetAccountAdjustment中,我看不到在任何地方定义了ClinicalEdit。

© www.soinside.com 2019 - 2024. All rights reserved.