|
|||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionAll 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 Here is the list of previous articles:
Running the DemoTo 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.
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.
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 imagesThe ASP.NET demo uses 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 <asp:Image … ImageUrl=
'<%# PhotoThumbnailURL((string) DataBinder.Eval(Container.DataItem, "OID")) %>'>
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 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);
SummaryThe 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 << Back | Next >>
|
||||||||||||||||||||||||||||||||||||||||||||