使用三层架构从数据库中检索数据 [英] data retrieval from database using three tier Architecture

查看:107
本文介绍了使用三层架构从数据库中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

属性层

<前lang =cs> public string MemberID
{
get { return _MemberID; }
set {_MemberID = value ; }
}





DATAACCESS LAYER

  public  DataSet Max_Member_Id(Configure_MasterPL obj,Member_MasterPL objmem)
{

SqlCon。 Open ();
sqlCmd = new SqlCommand( SELECT ISNULL(MAX(CONVERT(NUMERIC,MEMNO)),0)+ 1 FROM MEMBER_MASTER WITH(NOLOCK),SqlCon);
objmem.MemberID = Convert.ToString(sqlCmd.ExecuteScalar());
sqlCmd.Dispose();
SqlCon.Close();

返回ds;

}







BUSSINESSACCESS LAYER



  public  DataSet MaxMemcode(Configure_MasterPL obj,Member_MasterPL memobj)
{
return objMember.Max_Member_Id(obj,memobj);
}









演示层

  private   void  max()
{
string MEM_CODE = ;
DataSet ds1 = new DataSet();
objMemberMasterPL.MemberID = 0;
ds1 = objMemberMasterBAL.MaxMemcode(objMemberMasterPL);

dt = ds1.Tables [ 0 ];
ArrayList ar = new ArrayList();
if (dt.Rows.Count > 0
{
for int i = < span class =code-digit> 0 ; i < dt.Rows.Count; i ++)
{
MEM_CODE = dt.Rows [i] [ MEMNO]。ToString();

ar.Add(MEM_CODE);
}
ar.Sort();


}
ds1.Clear();
}



它无法读取表示层中的数据,plz hlep me ,, plz ,,,

解决方案

首先,您还没有为您的方法声明正确的数据类型,从而让您感到困惑。这是你的代码的重新排列,这是有意义的。

在数据访问层中



//将返回类型更改为字符串,因为你正在使用ExecuteScalar。

//您可以根据返回类型更改方法类型。

  public   string  Max_Member_Id(Configure_MasterPL obj,Member_MasterPL objmem)
{
SqlCon.Open();
sqlCmd = new SqlCommand( SELECT ISNULL (MAX(CONVERT(NUMERIC,MEMNO)),0)+1 FROM MEMBER_MASTER WITH(NOLOCK),SqlCon);
objmem.MemberID = Convert.ToString(sqlCmd.ExecuteScalar());
sqlCmd。 Dispose();
SqlCon.Close();

返回objmem.MemberID;
}





商务层

//更改类型字符串

  public 字符串MaxMemcode(Configure_MasterPL obj,Member_MasterPL memobj)
{
return objMember.Max_Member_Id(obj,memobj);
}





在表示层中

// ExecuteScalar方法检索单个值(例如来自数据库的聚合值。因此你无法为数据集分配。

  private   void  max()
{
string MEM_CODE = ;
// DataSet ds1 = new DataSet();
objMemberMasterPL.MemberID = 0;

// 获取最大代码
MEM_CODE = objMemberMasterBAL。 MaxMemcode(objMemberMasterPL);

// ds1 = objMemberMasterBAL.MaxMemcode(objMemberMasterPL);

// 根据此处提供的方法,所有这些都不是必需的。

/ * dt = ds1.Tables [0];
ArrayList ar = new ArrayList();
if(dt.Rows.Count> 0)
{
for(int i = 0; i< dt.Rows.Count; i ++)
{
MEM_CODE = dt.Rows [i] [MEMNO]。ToString();

ar.Add(MEM_CODE);
}
ar.Sort();


}
ds1.Clear(); * /

}





希望这会有所帮助。


PROPERTY LAYER

public string MemberID
     {
         get { return _MemberID; }
         set { _MemberID = value; }
     }



DATAACCESS LAYER

public DataSet Max_Member_Id(Configure_MasterPL obj, Member_MasterPL objmem)
   {

       SqlCon.Open();
       sqlCmd = new SqlCommand("SELECT ISNULL(MAX(CONVERT(NUMERIC,MEMNO)),0)+1 FROM MEMBER_MASTER WITH (NOLOCK), SqlCon);
       objmem.MemberID= Convert.ToString(sqlCmd.ExecuteScalar());
       sqlCmd.Dispose();
       SqlCon.Close();

       return ds;

   }




BUSSINESSACCESS LAYER

public DataSet MaxMemcode(Configure_MasterPL obj, Member_MasterPL memobj)
{
    return objMember.Max_Member_Id(obj,memobj);
}





PRESENTATION LAYER

private void max()
{
 string MEM_CODE = "";
        DataSet ds1 = new DataSet();
        objMemberMasterPL.MemberID = "0";        
        ds1 = objMemberMasterBAL.MaxMemcode(objMemberMasterPL);     
       
        dt = ds1.Tables[0];
        ArrayList ar = new ArrayList();
        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                MEM_CODE = dt.Rows[i]["MEMNO"].ToString();
               
                ar.Add(MEM_CODE);
            }
            ar.Sort();
          
           
    }
        ds1.Clear();
}


it can'nt read data in presentation layer,, plz hlep me,,plz,,,

解决方案

First of all you have not used to declare the proper data type for your methods and thus make you to get confused. Here is the rearrangement of your code which would make sense.
In Data Access Layer

//Change the return type as string since you are using ExecuteScalar.
//You can change the method type based on the return type.

public string Max_Member_Id(Configure_MasterPL obj, Member_MasterPL objmem)
{
       SqlCon.Open();
       sqlCmd = new SqlCommand("SELECT ISNULL(MAX(CONVERT(NUMERIC,MEMNO)),0)+1 FROM MEMBER_MASTER WITH (NOLOCK), SqlCon);
       objmem.MemberID= Convert.ToString(sqlCmd.ExecuteScalar());
       sqlCmd.Dispose();
       SqlCon.Close();

       return objmem.MemberID;
}



In Bussiness Layer
//Change the type string

public string MaxMemcode(Configure_MasterPL obj, Member_MasterPL memobj)
{
    return objMember.Max_Member_Id(obj,memobj);
}



In Presentation Layer
//ExecuteScalar method to retrieve a single value (for example, an aggregate value) from a database. Thus you can not assign that for the DataSet.

private void max()
{
        string MEM_CODE = "";
        //DataSet ds1 = new DataSet();
        objMemberMasterPL.MemberID = "0";        
         
        //Get the max code
        MEM_CODE= objMemberMasterBAL.MaxMemcode(objMemberMasterPL);  
   
        //ds1 = objMemberMasterBAL.MaxMemcode(objMemberMasterPL);     
       
        //All these are not required according to your methods provided here.

        /*dt = ds1.Tables[0];
        ArrayList ar = new ArrayList();
        if (dt.Rows.Count > 0)
        {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                MEM_CODE = dt.Rows[i]["MEMNO"].ToString();
               
                ar.Add(MEM_CODE);
            }
            ar.Sort();
          
           
        }
        ds1.Clear();*/
}



Hope this would help in some way or other.


这篇关于使用三层架构从数据库中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆