473,406 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

"Object variable or With block variable not set." issue

adascat
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")

Expand|Select|Wrap|Line Numbers
  1.  
  2. Imports System.Data
  3. Imports System.Data.OleDb
  4.  
  5. Partial Class _Default
  6.     Inherits System.Web.UI.Page
  7.  
  8.     Private ResultsGrid As Object
  9.  
  10.  
  11.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  12.         If Not IsPostBack Then
  13.             Dim aConnection = New OleDbConnection
  14.             Dim aConnectionString As String
  15.             Dim SQLQuery As String
  16.             Dim aDataAdapter = New OleDbDataAdapter
  17.             Dim aDataSet = New DataSet
  18.             aConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" & _
  19.                 Server.MapPath("/App_Data/abc.accdb")
  20.             aConnection.ConnectionString = aConnectionString
  21.             SQLQuery = "Select TranslatorEmail From Translator Where IsTranslatorRegistered = False"
  22.             aDataAdapter.SelectCommand = New OleDbCommand(SQLQuery, aConnection)
  23.             aDataAdapter.SelectCommand.Connection.Open()
  24.             aDataAdapter.Fill(aDataSet, "Translator Awaiting Approval")
  25.             ResultsGrid.DataSource = aDataSet.Tables("Translator Awaiting Approval")
  26.             Page.DataBind()
  27.  
  28.         End If
  29.     End Sub
  30.  
  31. End Class
Apr 24 '11 #1
3 4516
Frinavale
9,735 Expert Mod 8TB
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
Apr 27 '11 #2
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:
Expand|Select|Wrap|Line Numbers
  1. [OleDbException (0x80004005): Unrecognized database format 'C:\Users\Lili\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\App_Data\CS5012ProjectAY201011.accdb'.]
  2.    System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +337
  3.    System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +86
  4.    System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +31
  5.    System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +76
  6.    System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +126
  7.    System.Data.OleDb.OleDbConnection.Open() +43
  8.    WebApplication1.WebForm2.Button1_Click(Object sender, EventArgs e) in C:\Users\Lili\Documents\Visual Studio 2010\Projects\WebApplication1\WebApplication1\Registration.aspx.vb:30
  9.    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
  10.    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
  11.    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
  12.    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
  13.    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
  14.    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
  15.  
  16. Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
  17.  
It feels like getting messy now :(
Apr 27 '11 #3
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")

Expand|Select|Wrap|Line Numbers
  1. # Imports System.Data
  2. # Imports System.Data.OleDb
  3. #  
  4. # Partial Class _Default
  5. #     Inherits System.Web.UI.Page
  6. #  
  7. #  
  8. #     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  9. #         If Not IsPostBack Then
  10. #             Dim aConnection = New OleDbConnection
  11. #             Dim aConnectionString As String
  12. #             Dim SQLQuery As String
  13. #             Dim aDataAdapter = New OleDbDataAdapter
  14. #             Dim aDataSet = New DataSet
  15. #             aConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source =" & _
  16. #                 Server.MapPath("/App_Data/abc.accdb")
  17. #             aConnection.ConnectionString = aConnectionString
  18. #             SQLQuery = "Select TranslatorEmail From Translator Where IsTranslatorRegistered = False"
  19. #             aDataAdapter.SelectCommand = New OleDbCommand(SQLQuery, aConnection)
  20. #             aDataAdapter.SelectCommand.Connection.Open()
  21. #             aDataAdapter.Fill(aDataSet, "Translator Awaiting Approval")
  22. #             Gridview1.DataSource = aDataSet.Tables("Translator Awaiting Approval")
  23. #             Gridview1.DataBind()
  24. #  
  25. #         End If
  26. #     End Sub
  27. #  
  28. # End Class
  29.  
Any clue on why this is happening?
Apr 28 '11 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
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, ...
11
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...
3
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...
9
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...
0
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'...
1
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...
10
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...
1
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
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...
0
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...
0
marktang
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,...
0
Oralloy
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,...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.