Paging Problem - Page Error - Novice Alert

Posted on 2004-12-01
Last Modified: 2008-01-09
ASP.NET, VB.NET, Access Db

I am working on my first Asp.NET web page.  All was going pretty good until I tried to add the paging code to the page.  Now I am getting the following Error: BC30454: Expression is not a method. - Line 76:  objPageConn As New OleDbConnection(ConfigurationSettings.AppSettings("Contacts"))

I can't find any information on this so I may as well embarass myself by posting my novice code.  Hopefully someone can point out the problem or suggest how I may improve my code in order for it to work.


<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>

<script runat="server">

    Sub Page_Load(s as object, e as eventargs)
        Dim dsContacts As DataSet
        Dim objConn As OleDbConnection
        Dim daContacts As OleDbDataAdapter
        Dim strPath As String
        dsContacts = New DataSet()
        objConn = New OleDbConnection(ConfigurationSettings.AppSettings("Contacts"))
        daContacts = New OleDbDataAdapter("SELECT FirstName As [First Name], LastName As [Last Name], Department, Division, Phone, Fax FROM contacts", objConn)
        daContacts.Fill(dsContacts, "Contacts")
        dgContacts.DataSource = dsContacts

        Dim ddlDepartmentCommand As OleDbCommand
        ddlDepartmentCommand = New OleDbCommand("SELECT Department FROM departments ORDER BY Department ASC", objConn)
        Dim dtrDepartment As OleDbDataReader
        dtrDepartment = ddlDepartmentCommand.ExecuteReader()
        ddlDepartment.DataSource = dtrDepartment
        ddlDepartment.DataTextField = "department"
        Dim defaultItemDept as New ListItem
        defaultItemDept.Text = "Select Department"
        defaultItemDept.Value = ""
        ddlDepartment.Items.Insert(0, defaultItemDept)

        Dim ddlDivisionCommand As OleDbCommand
        ddlDivisionCommand = New OleDbCommand("SELECT division FROM divisions ORDER BY division ASC", objConn)
        Dim dtrDivision As OleDbDataReader
        dtrDivision = ddlDivisionCommand.ExecuteReader()
        ddlDivision.DataSource = dtrDivision
        ddlDivision.DataTextField = "division"
        Dim defaultItemDiv as New ListItem
        defaultItemDiv.Text = "Select Division"
        defaultItemDiv.Value = ""
        ddlDivision.Items.Insert(0, defaultItemDiv)


    End Sub

    Sub BindDataGrid( strSortField As String)

        Dim objSortConn As OleDbConnection
        Dim cmdSortSelect As OleDbCommand

        objSortConn = New OleDbConnection(ConfigurationSettings.AppSettings("Contacts"))
        cmdSortSelect = New OleDbCommand("SELECT FirstName As [First Name], LastName As [Last Name], Department, Division, Phone, Fax FROM contacts ORDER BY " & strSortField, objSortConn)
        dgContacts.DataSource = cmdSortSelect.ExecuteReader()

     End Sub

     Sub dgContacts_SortCommand(S as Object, E as DataGridSortCommandEventArgs)
     End Sub

    Sub BindDataGridPaging
        Dim objPageConn As OleDbConnection
        Dim daPageContacts As OleDbDataAdapter
        Dim dsPageContacts As DataSet

        objPageConn As New OleDbConnection(ConfigurationSettings.AppSettings("Contacts"))
        daPageContacts = New OleDbDataAdapter("SELECT FirstName As [First Name], LastName As [Last Name], Department, Division, Phone, Fax FROM contacts Order by LastName ASC")
        dsPageContacts = New DataSet

        dgContacts.DataSource = dsPageContacts

     End Sub

     Sub dgContacts_PageIndexChanged(S as Object, E as DataGridPageChangedEventArgs)
        dgContacts.CurrentPageIndex = e.NewPageIndex
     End Sub


    <form runat="server">
        <asp:TextBox id="txtLastName" runat="server" columns="30"></asp:TextBox>
        <br />
        <asp:TextBox id="txtFirstName" runat="server" columns="30"></asp:TextBox>
        <br />
        <asp:DropDownList id="ddlDepartment" runat="server">
            <asp:listitem>Select Department</asp:listitem>
        <br />
        <asp:DropDownList id="ddlDivision" runat="server">
            <asp:listitem>Select Division</asp:listitem>
        <br />
        <br />
        <asp:DataGrid id="dgContacts" AllowSorting="True" OnSortCommand="dgContacts_SortCommand" AllowPaging="True" PageSize="12" OnPageIndexChanged="dgContacts_PageIndexChanged" CellPadding="5" Runat="server"></asp:DataGrid>

Question by:painted
    LVL 24

    Accepted Solution

    Sub BindDataGridPaging
            Dim objPageConn As OleDbConnection
            Dim daPageContacts As OleDbDataAdapter
            Dim dsPageContacts As DataSet

            objPageConn = New OleDbConnection(ConfigurationSettings.AppSettings("Contacts"))
    LVL 24

    Expert Comment

    by:Jeff Certain
    ** It's that last = sign that was an "AS"
    LVL 6

    Expert Comment

    You might need to import the System.Configuration namespace as well to be able to user ConfigurationSettings.AppSettings
    LVL 2

    Author Comment

    Thanks, Chaosian.

    That got rid of the  BC30454: Expression is not a method error.  

    I also noticed when I correct the As to an = that I had left the connection out of the next line.  When I added the objPageConn, I got a new error: AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID dgContacts when Allow Paging is set to true and the selected datasource does not implement ICollection....whew!

    I've been reading about paging tonight since I left work and evidently, I'm really not understanding enough about paging (or ASP.NET for that matter) to really get my head around it.  Tomorrow I'm going to try "AllowCustomPaging" to see if that will work better for me.  I've no clue about the "ICollection".  

    Thanks, ryerras.

     I'll try your suggestion in the morning.  I've been getting the data, before adding the paging, that is.  Maybe that will make a difference with the paging.

    One other note:  With the record paging, I will not need the first sub that populates the datagrid, will I?


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    This video discusses moving either the default database or any database to a new volume.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now