Click here to Skip to main content
15,880,905 members
Articles / Web Development / ASP.NET

An Introduction to a Post-relational Database for .NET: Matisse - Part 6

Rate me:
Please Sign up or sign in to vote.
4.45/5 (21 votes)
2 May 20043 min read 65.9K   966   37   1
ASP.NET programming with a post-relational database.

Sample Image - introtomatisse_part6.gif

Introduction

All the basics of the Matisse post-relational database have already been covered by this series of articles, along with its advantages, such as ease of use and better performance.

This article covers ASP.NET programming with the post-relational database. I have created two demo programs to illustrate this article. The first one is a Windows application that loads data with images into a database. The second one is an ASP.NET application that retrieves the images with meta data from the database and displays them using DataList. The programs are straightforward but there are a few tips that make the programs more compact and provide better performance.

Here is the list of previous articles:

  • Part 1: Overview of Matisse
  • Part 2: Schema definition
  • Part 3: .NET programming to insert objects
  • Part 4: Using ADO.NET to retrieve objects
  • Part 5: Using Object-APIs for better performance

Running the Demo

To compile and run the demo applications, first download the source file attached at the beginning of this article. Create a new blank solution in Visual Studio .NET 2003 and add three projects: a Class Library (DbSchema), a Windows Application (MediaDemo), and an ASP.NET application (MediaDemoASP) as shown in the next figure. Extract all the files from the downloaded zip file, and add the files to the three projects accordingly.

ASP.NET projects

In the Matisse Enterprise Manager, start the ‘media’ database and import the ODL file demo.odl included in the zip file to load the database schema (Select the media database icon, right click on it, select Schema --> Import ODL Schema).

Compile the three .NET projects and run the MediaDemo Windows application to load the data. You will see the following window, and then select the folder photos which you downloaded with other source files, and click the ‘Load Data’ button to load the image data into the database. After loading the data, you can view the imported data in the ‘View Data’ tab.

Loading Data

To run the ASP.NET demo from Visual Studio .NET, select the ‘MediaDemoASP’ project as ‘Startup Project’ and select ‘StartForm.aspx’ as ‘Start Page’.

Retrieving Images

The ASP.NET demo uses DataList Web Control to display a list of photos with descriptions, four photos in each page as shown in the figure at the top of this article. It uses the LIMIT and OFFSET clauses in the SELECT statement to limit the number of rows returned, starting from a certain offset. Note that the SELECT statement returns the OID (Object Identifier, equivalent with primary key) column as well, which will be used to retrieve images efficiently. The rest is textbook programming with the DataList control.

C#
string query =
    "SELECT Title, Description, OID FROM Photo ORDER BY Title " +
    " LIMIT " + PageSize +
    " OFFSET " + (CurrentPage * PageSize);

// For DataList
MtCommand cmd = db.CreateCommand();
cmd.CommandText = query;
MtDataReader reader = (MtDataReader) cmd.ExecuteReader();
DataList1.DataSource = reader;
DataList1.DataBind();
reader.Close();

In the web form that contains the DataList, specify the thumbnail image URL using the OID column as follows:

C#
<asp:Image … ImageUrl=
'<%# PhotoThumbnailURL((string) DataBinder.Eval(Container.DataItem, "OID")) %>'>

PhotoThumbnailURL which takes OID as an input parameter is defined as follows:

C#
public string PhotoThumbnailURL(string oid)
{
    return "ReadThumbnail.aspx?oid=" + oid +
           "&dbname=" + (string) ViewState["DbName"];
}

The next piece of code from ReadThumbnail.aspx.cs parses the passed OID string into an integer. Then, it creates a Photo object, which is a Matisse object, using a constructor that takes the OID (line A). Since it does not use SQL statements, it retrieves the object faster from the database. To get the thumbnail image data, access the Thumbnail property of the Photo object (line B).

C#
byte[] imgdata = null;
db.Open();
db.StartVersionAccess();

/* Request.QueryString["oid"] returns OID in the format of '0x1234' */
int oid = Int32.Parse(Request.QueryString["oid"].Substring(2),
    System.Globalization.NumberStyles.AllowHexSpecifier);

// retrieve the Movie object with the OID
Photo photo = new Photo(db, oid);   // line A

// retrieve thumbnail image data of the movie from the database
imgdata = photo.Thumbnail;          // line B

db.EndVersionAccess();
db.Close();

if ( null != imgdata )
    Response.BinaryWrite(imgdata);

Summary

The article showed a simple ASP.NET application that retrieves image data along with some descriptions from the Matisse database and displays the data using the DataList control.

<< Back | Next >>

History

  • 3rd May, 2004: Initial version

License

This article has no explicit license attached to it, but may contain usage terms in the article text or the download files themselves. If in doubt, please contact the author via the discussion board below. A list of licenses authors might use can be found here.


Written By
Web Developer
United States United States
John is a software consultant and currently working for a large .NET project. He has an extensive experience in object-oriented technologies for more than 15 years ranging from Smalltalk, C++, Java, .NET to databases.

Comments and Discussions

 
QuestionCompile??? Pin
Small Rat19-Aug-04 18:56
Small Rat19-Aug-04 18:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.