Got title problem for the codes below, can anyone help to have a look what's wrong here? Thanks a million. - A newbie
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 variable or With block variable not set.
Source Error:
Line 24: ResultsGrid.DataSource = aDataSet.Tables("Translator Awaiting Approval") -
-
Imports System.Data
-
Imports System.Data.OleDb
-
-
Partial Class _Default
-
Inherits System.Web.UI.Page
-
-
Private ResultsGrid As Object
-
-
-
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
If Not IsPostBack Then
-
Dim aConnection = New OleDbConnection
-
Dim aConnectionString As String
-
Dim SQLQuery As String
-
Dim aDataAdapter = New OleDbDataAdapter
-
Dim aDataSet = New DataSet
-
aConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" & _
-
Server.MapPath("/App_Data/abc.accdb")
-
aConnection.ConnectionString = aConnectionString
-
SQLQuery = "Select TranslatorEmail From Translator Where IsTranslatorRegistered = False"
-
aDataAdapter.SelectCommand = New OleDbCommand(SQLQuery, aConnection)
-
aDataAdapter.SelectCommand.Connection.Open()
-
aDataAdapter.Fill(aDataSet, "Translator Awaiting Approval")
-
ResultsGrid.DataSource = aDataSet.Tables("Translator Awaiting Approval")
-
Page.DataBind()
-
-
End If
-
End Sub
-
-
End Class
3 4516
Whenever you retrieve anything from an external source (like a database in your case) you should check to make sure that you have actually retrieved the data.
It sounds like your retrieval of data failed in some way.
Or you don't have a table named "Translator Awaiting Approval" in your DataSet.
Either way, you will get a System.NullReferenceException when you attempt to use an object that hasn't been initialized. You will see it when you try to call a method or use a Property on "Nothing" or "Null".
-Frinny
Thank you Frinny.
In a different page, I met another problem while attempting to retrieve data from the accdb file, error msg is listed below and I guess it's the data file connection problem?
Exception Details: System.Data.OleDb.OleDbException: Unrecognized database format 'C:\Users\Lili\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\App_ Data\CS5012ProjectAY201011.accdb'.
Stack Trace: - [OleDbException (0x80004005): Unrecognized database format 'C:\Users\Lili\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\App_Data\CS5012ProjectAY201011.accdb'.]
-
System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +337
-
System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +86
-
System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +31
-
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +76
-
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
-
System.Data.OleDb.OleDbConnection.Open() +43
-
WebApplication1.WebForm2.Button1_Click(Object sender, EventArgs e) in C:\Users\Lili\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\Registration.aspx.vb:30
-
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
-
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
-
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
-
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
-
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
-
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
-
-
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
-
It feels like getting messy now :(
I think I got the above issues(db format unrecognized) solved by changed the provider version to 12 instead of 4 and changed the provider info in the web.config. :)
And the "Object variable or With block variable not set." issue now becomes "Object reference not set to an instance of an object"! This page is working well seperately, however when I generate the view for main default page, it anyhow points to page of below codes, claiming that:
System.NullReferneceException: Object reference not set to an instance of an object.
Problematic line:
Gridview1.DataSource = aDataSet.Tables("Results") -
# Imports System.Data
-
# Imports System.Data.OleDb
-
#
-
# Partial Class _Default
-
# Inherits System.Web.UI.Page
-
#
-
#
-
# Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
-
# If Not IsPostBack Then
-
# Dim aConnection = New OleDbConnection
-
# Dim aConnectionString As String
-
# Dim SQLQuery As String
-
# Dim aDataAdapter = New OleDbDataAdapter
-
# Dim aDataSet = New DataSet
-
# aConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" & _
-
# Server.MapPath("/App_Data/abc.accdb")
-
# aConnection.ConnectionString = aConnectionString
-
# SQLQuery = "Select TranslatorEmail From Translator Where IsTranslatorRegistered = False"
-
# aDataAdapter.SelectCommand = New OleDbCommand(SQLQuery, aConnection)
-
# aDataAdapter.SelectCommand.Connection.Open()
-
# aDataAdapter.Fill(aDataSet, "Translator Awaiting Approval")
-
# Gridview1.DataSource = aDataSet.Tables("Translator Awaiting Approval")
-
# Gridview1.DataBind()
-
#
-
# End If
-
# End Sub
-
#
-
# End Class
-
Any clue on why this is happening?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jason C.Y. Chung |
last post by:
Hello everyone,
I am looking for a used book for "computing concepts with C++ essentials,
3rd ed." by Horstmann, Cay.
If you have one and want to sell it, please let me know.
Thanks,
...
|
by: Florian Loitsch |
last post by:
I'm currently writing a JS->Scheme compiler (which, using Bigloo,
automatically yields a JS->C, JS->JVM, JS->.NET compiler), and have a
question concerning the function-parameters:
According to...
|
by: Paul |
last post by:
I have an Access 2000 database with a form that is giving me some
major headaches. When you open the form, it displays all records and
allows editing, but has AllowAdditions set to False so that...
|
by: axs221 |
last post by:
I am trying to move some of our large VBA Access front-end file into
ActiveX DLL files. I created two DLL files so far, one was a module
that contains code to integrate into the QuickBooks...
|
by: Achim Domma |
last post by:
Hi,
I try to develop a localized Asp.Net 1.1 application. I have added two
resource files to my app, which are called 'Labels.resx' and
'Labels.de.resx'. If I compile the app, I see a 'de'...
|
by: Dameon99 |
last post by:
Hi,
I have just spent many hours debugging my code and now when I run it I get the following error:
"An access violation (Segmentation fault) raised in your program"
I have researched on this...
|
by: nspader |
last post by:
I want to start out saying I am a novice code writer. I am trying to send a report via email based on each supplier. The code below is what I am using. I need to base recordset on Form, report...
|
by: dehboy |
last post by:
Here's the deal. I'm trying to write an excel macro in VBA that will take a bunch of data and create a nice bubble chart out of it. First, it checks if the row I'm adding to the chart is the first...
|
by: principal |
last post by:
I am trying to install Oracle 8i on OS : Vista ; Processor :Intel Core2 Duo in my laptop. Upto an 87% of installation is complete when it raises an error, 'Problems occcured with jrew.exe. Cannot...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |