• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 515
  • Last Modified:

Paging Problem - Page Error - Novice Alert

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.

Thanks,
painted

<%@ 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"))
        objConn.Open()
        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
        dgContacts.DataBind()


        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"
        ddlDepartment.DataBind()
        Dim defaultItemDept as New ListItem
        defaultItemDept.Text = "Select Department"
        defaultItemDept.Value = ""
        ddlDepartment.Items.Insert(0, defaultItemDept)
        dtrDepartment.Close()


        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"
        ddlDivision.DataBind()
        Dim defaultItemDiv as New ListItem
        defaultItemDiv.Text = "Select Division"
        defaultItemDiv.Value = ""
        ddlDivision.Items.Insert(0, defaultItemDiv)


        objConn.Close()

    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)
        objSortConn.Open()
        dgContacts.DataSource = cmdSortSelect.ExecuteReader()
        dgContacts.DataBind()
        objSortConn.Close()

     End Sub

     Sub dgContacts_SortCommand(S as Object, E as DataGridSortCommandEventArgs)
        BindDataGrid(e.SortExpression)
     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")
        objPageConn.Open()
        dsPageContacts = New DataSet
        daPageContacts.Fill(dsPageContacts)

        dgContacts.DataSource = dsPageContacts
        dgContacts.DataBind()
        objPageConn.Close()

     End Sub

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



</script>

<html>
<head>
</head>
<body>
    <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>
        </asp:DropDownList>
        <br />
        <asp:DropDownList id="ddlDivision" runat="server">
            <asp:listitem>Select Division</asp:listitem>
        </asp:DropDownList>
        <br />
        <br />
        <asp:DataGrid id="dgContacts" AllowSorting="True" OnSortCommand="dgContacts_SortCommand" AllowPaging="True" PageSize="12" OnPageIndexChanged="dgContacts_PageIndexChanged" CellPadding="5" Runat="server"></asp:DataGrid>
    </form>
</body>
</html>




0
painted
Asked:
painted
  • 2
1 Solution
 
Jeff CertainCommented:
Sub BindDataGridPaging
        Dim objPageConn As OleDbConnection
        Dim daPageContacts As OleDbDataAdapter
        Dim dsPageContacts As DataSet

        objPageConn = New OleDbConnection(ConfigurationSettings.AppSettings("Contacts"))
0
 
Jeff CertainCommented:
** It's that last = sign that was an "AS"
0
 
ryerrasCommented:
You might need to import the System.Configuration namespace as well to be able to user ConfigurationSettings.AppSettings
0
 
paintedAuthor Commented:
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?

painted  
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now