Read a record from an Access database

Last post 07-06-2008 2:10 PM by Mikesdotnetting. 5 replies.

Sort Posts:

  • Read a record from an Access database

    07-04-2008, 7:44 AM
    • Loading...
    • Tikunim
    • Joined on 03-18-2008, 4:29 PM
    • Posts 21

    I'm a newbie using VWD 2008 Express edition.  I am trying to insert code on each aspx page to read a record from a table within my database, and update the page title and meta tags on my webpage.

    Right now I use a datalist control to access the data and  use the following code.

    Protected Sub DataList2_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
            Dim recordcontent As String
            If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem Then
                RecordContent = CType(DataBinder.Eval(e.Item.DataItem, "title"), String) & vbCrLf
                Page.Title = RecordContent
            End If
        End Sub

     

    This works.  But I think a cleaner way would be to open the database and read the record in the page load event and change the title there.  Or even to have some global code somewhere that when called will return to me the title and metatags that were read.  Are there any good tutorials out there that would point to me how to do this, or can someone just step me through it.

     Thanks!



     

    Filed under:
  • Re: Read a record from an Access database

    07-04-2008, 1:00 PM

    If I am dynamically populating the meta tags and page title from data I am already using on the page, I do exactly what you do.  It's the most efficient approach.  You don't want to be getting the same data out of the database twice for a page.

     

    Regards Mike
    [MVP - ASP/ASP.NET]
  • Re: Read a record from an Access database

    07-05-2008, 2:27 PM
    • Loading...
    • Tikunim
    • Joined on 03-18-2008, 4:29 PM
    • Posts 21

    I created the datalist explicitly to open the table and extract the title and meta data. The datalist is not visible to the user. The real data from the page comes from a different table. I could leave it this way, but thought that accessing the met and title data via code would be more efficient. 

  • Re: Read a record from an Access database

    07-05-2008, 3:58 PM

    Tikunim:
    I could leave it this way, but thought that accessing the met and title data via code would be more efficient. 
     

    Yes, it would be more efficient.  You won't be creating unnecessary objects, such as databound controls.

    Regards Mike
    [MVP - ASP/ASP.NET]
  • Re: Read a record from an Access database

    07-05-2008, 9:30 PM
    • Loading...
    • Tikunim
    • Joined on 03-18-2008, 4:29 PM
    • Posts 21

    I guess that leaves me at my original question.  Are there any good tutorials out there that would point to me how to do this, or can someone just step me through it.   i.e. write some code to open the database, do so sort of query, get my record and values, and then close the db.  

     

    Thanks 

  • Re: Read a record from an Access database

    07-06-2008, 2:10 PM

    Basic reading and writing to an Access Database code is here: http://www.mikesdotnetting.com/Article.aspx?ArticleID=26

     

    Regards Mike
    [MVP - ASP/ASP.NET]
Page 1 of 1 (6 items)
Microsoft Communities
Page view counter