473,394 Members | 1,893 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,394 software developers and data experts.

OleDbReader -Object reference not set to an instance of an object

maylortaylor
72 64KB
Expand|Select|Wrap|Line Numbers
  1.  Function AddUsersToDictionary()
  2.         Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ConfigurationManager.AppSettings("Database")
  3.         Dim dbConnection As OleDbConnection = New OleDbConnection(connectionString)
  4.  
  5.         Try
  6.             dbConnection.Open()
  7.             Dim queryString As String
  8.             queryString = "SELECT DISTINCT UserName FROM [User];"
  9.  
  10.             Dim dbCommand As OleDbCommand = New OleDbCommand
  11.             dbCommand.CommandText = queryString
  12.             dbCommand.Connection = dbConnection
  13.             'Dim dataAdapter As OleDbDataAdapter = New OleDbDataAdapter
  14.             'dataAdapter.SelectCommand = dbCommand
  15.             Dim rdr As OleDbDataReader = dbCommand.ExecuteReader()
  16.             While rdr.Read()
  17.                 'If UserDictionary.ContainsKey(rdr.Item("UserName")) = False Then
  18.                 UserDictionary.Add(rdr.Item("UserName").ToString, 1)
  19.                 'End If
  20.             End While
  21.  
  22.             rdr.Close()
  23.             'Dim clientName As String
  24.             'dbConnection.Open()
  25.             'clientName = dbCommand.ExecuteScalar()
  26.  
  27.  
  28.  
  29.         Catch ex As Exception
  30.             Console.WriteLine(ex.Message)
  31.             myLogger.Log(ex.Message)
  32.         Finally
  33.             dbConnection.Close()
  34.         End Try
  35.     End Function
The "Object reference not set to an instance of an object" error happens at the
Expand|Select|Wrap|Line Numbers
  1. "UserDictionary.add(rdr.item("UserName"),1)"
line. Any help?
May 10 '13 #1
0 1029

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

Similar topics

2
by: Pkpatel | last post by:
Hi, I keep getting this error every time I try to load crystalreportviewer on a webform with a dataset. Here is the error: -------------------------------------------------------- Server...
6
by: NewToDotNet | last post by:
I am getting "Object reference not set to an instance of an object. " when I attempt to open a C# windows service class in design view, although I was able to initially create the service and open...
4
by: Frawls | last post by:
Hi, I get the following error when trying to run a search on my aspx site, this error only occours if the product im searching for does not exist. Can anybody explain this please and help me...
2
by: jw56578 | last post by:
why am i getting the "Object reference not set to an instance of an object" error on all page registeration tags in my project. <%@ Page Language="vb" AutoEventWireup="false"...
3
by: nemo | last post by:
Hi, My application works fine on the localhost but spits this error as soon as I put it on the server. I know this error occurs when an object has not been instantiated prior to a reference, but...
3
by: Adam | last post by:
We have a web site that uses .vb for the web pages and .cs for a class module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does work with .NET 1.1. When trying to access a page...
7
by: Brett | last post by:
I'm not sure why I keep getting this error, "Object reference not set to an instance of an object". Private Function somefunction() as string Dim MyCurrentClass As New Class1 Try For i As...
6
by: kalaivanan | last post by:
hi, i am a beginner in c#. i have theoretical knowledge about object, reference and instance. but i want to know clearly about what is an object, reference and instance. can any one help me? or...
1
by: vishnu | last post by:
Hi, I am working on asp.net project which I converted the code fron VB to C# and instead of RaiseEvent in VB code I used the following code. using System; using System.Data; using...
4
by: livmacca | last post by:
Hi, I am new to VB .Net programming and is trying to create a webpage. I encountered the following error and is totally clueless on how to make it work: ...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...

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.