How to: Display Ads From a Database Using the AdRotator Web Server Control
The AdRotator control reads advertisement information from a data source, which contains one or more ad records. You can store ad information in a database table with a specific schema, and then use a data source control to read the ad records at run time. If you have an existing table with ad information, you can map the schema of your table to the fields that are required by the AdRotator control.
You can store ad information in any type of database, as long as you have the corresponding data source control for that database.
To create the database table for ads
If you do not already have a database table that contains the ad information, create a table with the following schema. All columns except ID are optional.
Note
Data types are provided as SQL Server types. If you are using a different database, substitute the appropriate corresponding type.
Column name
Data type
Description
ID
int
Primary key. This column can have any name.
ImageUrl
nvarchar(length)
The relative or absolute URL of the image to display for the ad.
href
nvarchar(length)
The target URL for the ad. If you do not provide a value, the ad is not a hyperlink.
AlternateText
nvarchar(length)
The text displayed if the image cannot be found. In some browsers, the text is displayed as a ToolTip. Alternate text is also used for accessibility so that users who cannot see the graphic can hear its description read out loud.
Keyword
nvarchar(length)
A category for the ad on which the page can filter.
Impressions
int(4)
A number that indicates the likelihood of how often the ad is displayed. The larger the number, the more often the ad will be displayed. The total of all impressions values in the XML file may not exceed 2,048,000,000 - 1.
Width
int(4)
The width of the image in pixels.
Height
int(4)
The height of the image in pixels.
If you have an existing database table with ad information in it, set the following properties of the AdRotator control to map your database table schema to the fields required by the control:
hrefField
Insert new records into the table with ad information.
To display ads from the database
Place a data source control, such as a SqlDataSource or AccessDataSource control, onto the page.
Configure the data source control with a connection string and query to select all of the records from the database table you created earlier.
Note
For information about using data source controls, see Data Source Web Server Controls.
Place an AdRotator control on the ASP.NET Web page where you want the ads to appear.
Set the AdRotator control's DataSourceID property to the ID of the data source control that you created earlier in step 1.
When the page runs, the AdRotator control will query the database for the ads and select one to display.
See Also
Tasks
How to: Display Ads From an XML File Using the AdRotator Web Server Control
How to: Select Ads in an AdRotator Web Server Control Programmatically