ASP.NET and VB.NET OleDbConnection Problem

Posted by Matt on Stack Overflow See other posts from Stack Overflow or by Matt
Published on 2008-10-12T09:47:16Z Indexed on 2010/04/03 6:23 UTC
Read the original article Hit count: 467

I'm working on an ASP.NET website where I am using an asp:repeater with paging done through a VB.NET code-behind file. I'm having trouble with the database connection though. As far as I can tell, the paging is working, but I can't get the data to be certain.

The database is a Microsoft Access database. The function that should be accessing the database is:

Dim pagedData As New PagedDataSource

Sub Page_Load(ByVal obj As Object, ByVal e As EventArgs)
    doPaging()
End Sub

Function getTheData() As DataTable
    Dim DS As New DataSet()
    Dim strConnect As New OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0;Data Source=App_Data/ArtDatabase.mdb")
    Dim objOleDBAdapter As New OleDbDataAdapter("SELECT ArtID, FileLocation, Title, UserName, ArtDate FROM Art ORDER BY Art.ArtDate DESC", strConnect)
    objOleDBAdapter.Fill(DS, "Art")

    Return DS.Tables("Art").Copy
End Function

Sub doPaging()
    pagedData.DataSource = getTheData().DefaultView
    pagedData.AllowPaging = True
    pagedData.PageSize = 2

    Try
        pagedData.CurrentPageIndex = Int32.Parse(Request.QueryString("Page")).ToString()
    Catch ex As Exception
        pagedData.CurrentPageIndex = 0
    End Try

    btnPrev.Visible = (Not pagedData.IsFirstPage)
    btnNext.Visible = (Not pagedData.IsLastPage)

    pageNumber.Text = (pagedData.CurrentPageIndex + 1) & " of " & pagedData.PageCount

    ArtRepeater.DataSource = pagedData
    ArtRepeater.DataBind()
End Sub

The ASP.NET is:

<asp:Repeater ID="ArtRepeater" runat="server">
    <HeaderTemplate>
        <h2>Items in Selected Category:</h2>
    </HeaderTemplate>  
    <ItemTemplate>
        <li>
            <asp:HyperLink runat="server" ID="HyperLink"
                NavigateUrl='<%# Eval("ArtID", "ArtPiece.aspx?ArtID={0}") %>'>
                <img src="<%# Eval("FileLocation") %>"
                    alt="<%# DataBinder.Eval(Container.DataItem, "Title") %>t"/> <br />
                <%# DataBinder.Eval(Container.DataItem, "Title") %>
            </asp:HyperLink>
        </li>
    </ItemTemplate>
</asp:Repeater>

© Stack Overflow or respective owner

Related posts about vb.net

Related posts about ASP.NET