In this example, we retrieve multiple records using System Filter Options and Caching records.
Multiple Records Retrieval
using (SqlConnection connect = new SqlConnection(Management.Application.SelectConnectionString))
{
connect.Open();
DataTable dt = Utilities.Database.GetDataTable("GenericContent", "SELECT top 3 StartDate, EndDate, Title from cprel_Generic Order by Title", connect);
dgContent.DataSource = dt;
dgContent.DataBind();
}
//SystemFilter and Cache
string name = "GenericContent";
SystemFilterOptions sfo = SystemFilterOptions.Enabled | SystemFilterOptions.CurrentAndFutureDate;
CpContent content = CpContent.GetCache(name, sfo);
string clearCache = HttpContext.Current.Request.QueryString.Get("ClearCache");
if (clearCache == "YES")content = null;
if (content == null)
{
content = new CpContent(name, sfo);
content.AddRelation("GenericB", "Top 4 StartDate, EndDate, Title", "Title");
content.InsertCache();
lblRetrieved.Text = "Retrieved From Database";
}
else lblRetrieved.Text = "Retrieved From Cache. <a href="Retrieve_Update_Records.aspx?ClearCache=YES">Clear Cache</a>";
dgContent2.DataSource = content;
dgContent2.DataBind();
In this Example we retrieve just one record using DataInfo.
Guid recID = new Guid("00032197-c479-4cbd-b341-24861e84d95a");
DataInfo di = new DataInfo(recID);
if (!di.Exists)
throw new NullReferenceException("This document no longer available or exists.");
lbTitle.Text = String.Format("<b>Record Title:</b> {0}<br><b>Record ID:</b> {1}", di.Attributes.Get("Title"), recID);
Keywords: Module, Retrieve Records
Related CodeSamples Records