Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am trying to connect to Access DB for my pager I am using with my DataList. Here is the error message I am getting and please I am a newbie.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 30:
Line 31: Private Sub GetCustomersPageWise(pageIndex As Integer)
Line 32: Dim ForumDataSource As String = ConfigurationManager.ConnectionStrings("ForumDataSource").ConnectionString
Line 33: Using con As New OleDbConnection(ForumDataSource)
Line 34: Using cmd As New OleDbCommand("GetCustomersPageWise", con)

Source File: E:\hosting\blueeyeweb\mainForum.aspx.vb Line: 32

What I have tried:

VB
Private Sub GetCustomersPageWise(pageIndex As Integer)
        Dim ForumDataSource As String = ConfigurationManager.ConnectionStrings("ForumDataSource").ConnectionString
        Using con As New OleDbConnection(ForumDataSource)
            Using cmd As New OleDbCommand("GetCustomersPageWise", con)
                cmd.CommandType = CommandType.StoredProcedure
                cmd.Parameters.AddWithValue("@PageIndex", pageIndex)
                cmd.Parameters.AddWithValue("@PageSize", PageSize)
                cmd.Parameters.Add("@RecordCount", OleDbType.Integer, 4)
                cmd.Parameters("@RecordCount").Direction = ParameterDirection.Output
                con.Open()
                Dim idr As IDataReader = cmd.ExecuteReader()
                DataList1.DataSource = idr
                DataList1.DataBind()
                idr.Close()
                con.Close()
                Dim recordCount As Integer = Convert.ToInt32(cmd.Parameters("@RecordCount").Value)
                Me.PopulatePager(recordCount, pageIndex)
            End Using
        End Using
    End Sub
Posted
Updated 4-Sep-17 9:54am
v3

Maybe you forgot to place the string "ForumDataSource" in the project Settings.
Alternatively replace this by a normal string:
VB
ConfigurationManager.ConnectionStrings("ForumDataSource").ConnectionString
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900