Synatx for fetching data using Generic and DataReader in DataAccess Layer.


public List<EmailTemplateBE> FetchEmailtemplate()
{

List<EmailTemplateBE> results = new List<EmailTemplateBE>();
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings[“Test”].ConnectionString);
SqlCommand cmd = new SqlCommand(“TemplateFetch”, con);
cmd.CommandType = CommandType.StoredProcedure;
using (con)
{
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
EmailTemplateBE obj = new EmailTemplateBE();
obj.Id = (int)dr[“Id”];
obj.Title = (string)dr[“Title”];
obj.Description = (string)dr[“Description”];
results.Add(obj);
}
dr.Close();

}
return results;

}

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.