views:

1000

answers:

4

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>
+1  A: 

If you need help with Connection Strings, this site is the ultimate resource!

http://www.connectionstrings.com/

Sklivvz
That site is great! Thanks
Matt
A: 

Are you creating the connection string by hand? If so...don't do that! Use the Server Explorer to create your connection. Then highlight it and go to the Properties window, and you'll see the connection string it uses.

Also, using the Server Explorer will let you browse through your tables and even open them up to see your data. At least that'll tell you for certain whether your data is accessible.

Kyralessa
I didn't know that! Thanks for that, it doesn't really solve my problem though. Using the connection string it gives me, I still don't have any data displaying though
Matt
A: 

Problem solved! Pretty much banging my head against the wall now considering how simple it was. It was the Page_Load, I changed it to the following:

Protected Sub Page_Load1(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    doPaging()
End Sub

And voila, it works!

Also, for the connection string, I ended up using:

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\ArtDatabase.mdb

Which works great.

Thanks for your help and input guys!

Matt
A: 

oledb connection to database

http://vb.net-informations.com/ado.net-dataproviders/ado.net-oledbconnection.htm

thanks.

bolton