【问题标题】:Need help in storing dynamic value using arraylist在使用 arraylist 存储动态值方面需要帮助
【发布时间】:2010-10-08 18:32:28
【问题描述】:

请有人帮助我如何使用 arraylist 动态存储值。每次我想添加患者详细信息时。这是我的代码层:

PatientDataLayer:

public class PatientData
{
    public string str = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString();
    public int AddPatient(Patient obj)
    {
        using (var con = new SqlConnection(str))
        {
            using (var com = new SqlCommand("AddPatient", con))
            {
                com.CommandType = CommandType.StoredProcedure;
                com.Parameters.AddWithValue("@Name", obj.Name);
                com.Parameters.AddWithValue("@Address", obj.Address);
                com.Parameters.AddWithValue("@DateOfBirth", obj.DateOfBirth);
                com.Parameters.AddWithValue("@Phone", obj.Phone);
                com.Parameters.AddWithValue("@EmergencyContact", obj.EmergencyContact);
                com.Parameters.AddWithValue("@DateOfRegistration", obj.DateOfRegistration);
                con.Open();
                com.ExecuteNonQuery();
                con.Close();
                return 0;                       
            }
        }
    }

PatientBusinessLayer:

public class PatientBusiness
{
    public void Add(Patient obj)
    {      
        PatientData pd = new PatientData();
        pd.AddPatient(obj);      
    }   
}

Patient.aspx.cs:

 protected void BtnAdd_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)   //validating the page
            return;
        string name = TxtName.Text;
        string address = TxtAddress.Text;
        DateTime dateofbirth =Convert.ToDateTime(TxtDateOfBirth.Text);
        int phone = Convert.ToInt32(TxtPhone.Text);
        int emergencyno=Convert.ToInt32(TxtContact.Text);
        DateTime registrationdate =Convert.ToDateTime(TxtRegistrationDate.Text);
        PatientBusiness PB = new PatientBusiness();
        Patient obj = new Patient();
        try
        {
            obj.Name = name;
            obj.Address = address;
            obj.DateOfBirth = dateofbirth;
            obj.Phone = phone;
            obj.EmergencyContact = emergencyno;
            obj.DateOfRegistration = registrationdate;
            PB.Add(obj);
            LblMessage.Text = "Patient has been added successfully";
            TxtName.Text = "";
            TxtAddress.Text = "";
            TxtDateOfBirth.Text = "";
            TxtPhone.Text = "";
            TxtContact.Text = "";
            TxtRegistrationDate.Text = "";
        }
        catch (Exception ee)
        {
            LblMessage.Text = ee.Message.ToString();
        }
        finally
        {
            PB = null;
        }   
    }

谢谢, 马苏姆

【问题讨论】:

  • 你到底想在这里用ArrayList做什么?您正在保存一个传递类型对象的单条记录...哪里需要列表?
  • 就像 Marc 说的,这里的问题到底是什么?

标签: c# arraylist


【解决方案1】:

我不明白你的问题,但是在查看了你的代码之后,我只能建议你考虑结合使用 ObjectDataSource 和 FormView 并停止在后面的代码中做“业务”。

【讨论】:

  • 我在代码隐藏中看不到任何“业务内容” - 仅将数据从控件移动到实体并调用业务层的 Add 方法...
  • 我的意思是表示层不是创建实体的最佳位置。 PL 不应该担心如何做,而是将所有数据交给业务层,让其完成工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-12-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-28
  • 1970-01-01
相关资源
最近更新 更多