In a data-driven website, there becomes a need to have only one page serve up different data, based on the call to the database. Naturally, you wouldn’t want to have the same Title on the page’s drag bar, and you certainly would like to have different Keywords in your meta tag along with every section of content received from the database. This tutorial will attempt to provide a simple example/overview of how to dynamically add, not only the content, but the Title of the page and the Keywords for the HTML Meta Tags in order to get you started in this direction.
First we’ll start with the database table structure. Keep in mind, I previously said ‘a simple way’, so, keeping that in mind, here would be four fields needed to do this:
- id (in MS Access, Autonumber/in SQL Server – Identity)
- Title
- Keywords
- Content – content for the page
For each section of content we plan to show in this page, when we enter the data into the table, we will, of course, make the fields not accept nulls.Since the ID field is autonumbering, we don’t need to worry about that field when inserting data. When we call this page (let’s call it ‘Content.aspx’), it will need a querystring added to it, which will be based on the ID field – something like ‘Content.aspx?id=1″. This way, we will then query the database in the Page_Load event, requesting record #1 from our table. it will then return the Title, Keys and the Content for the page. Outside of Page_Load, we dimension the variables:
Dim sKeys, sTitle, sContent as String
We’ll only need a DataReader to retrieve this information, and we can put the information into variables for use within the page, like this:
While objDR.Read
sContent=objDR("Content")
sTitle=objDR("Title")
sKeys=objDR("keywords")
End While
Continues…