You must Sign In to post a response.
  • Category: .NET

    Retrieve data from DAL to Presentation

    Question:
    Presentation layer will hit DAL layer only once to fetch the data throughout the lifecycle of an application to fetch the data , subsequent calls will not touch the DAL Layer instead to get the data

    How to do this?
  • #768232
    Dear Friend
    You can use given code snippet as guideline know about how to pass datareader value from DAL to Presentation layer

    public class HomeDAL
    {
    public List<Person> DefaultSearchFriends(long userid)
    {
    SqlConnection SocialConn = new SqlConnection(connstr);

    using (SqlCommand comm = new SqlCommand("proc_FriendsSearch", SocialConn))
    {
    comm.CommandType = CommandType.StoredProcedure;
    comm.Parameters.AddWithValue("@userid", userid);
    SocialConn.Open();
    SqlDataReader dr = comm.ExecuteReader(CommandBehavior.CloseConnection);

    var persons = new List<Person>();

    while (dr.Read())
    persons.Add(new Person { Name = dr["StudentName"], Fname = dr["Fname"] });

    dr.Close();

    return persons;
    }
    }
    }

  • #768252
    Hi,

    You have to make such provision so that you code will not call DAL lots of times to fetch the data.
    Also you may use following so that you can store the fetched value for a long time:
    1. 'DataTable' instead of 'DataReader' : As Datatable is a disconnected architecture, you can fetch and store values into it and close the connection.
    2. Session' variables: Persists for long time.


  • Sign In to post your comments