Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
PROPERTY LAYER
C#
public string MemberID
     {
         get { return _MemberID; }
         set { _MemberID = value; }
     }


DATAACCESS LAYER
SQL
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

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




PRESENTATION LAYER
C#
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,,,
Posted
Updated 24-Sep-13 2:50am
v3
Comments
[no name] 24-Sep-13 7:32am    
The error you received when you debugged your code would have told you exactly what the problem was. "ds" is not defined in your Max_hodMember_Id method.
Member 9959371 24-Sep-13 8:55am    
so,, not ds,,it is ds1,,plz hlep me
[no name] 24-Sep-13 9:10am    
No it is clearly "ds" that you are trying to return and that does not exist. You need to learn how to debug your code.
Member 9959371 24-Sep-13 9:17am    
the data can't read in presentationlayer ,, to throw error 'array not bound'
[no name] 24-Sep-13 9:48am    
That is because you are returning something called "ds" from your Max_Member_Id method that is not defined! Can you not read?

1 solution

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.
C#
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
SQL
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.
C#
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.
 
Share this answer
 
v2
Comments
Member 9959371 24-Sep-13 12:20pm    
Thanks alot ,,,

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900