473,406 Members | 2,620 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 reference not set to an instance of an object. For Loop

maylortaylor
72 64KB
Expand|Select|Wrap|Line Numbers
  1. Function FindUserByCriteria(ByVal _state As String, ByVal _county As String, ByVal _status As String, ByVal _client As String, ByVal _department As String, ByVal _ordernumber As String) As DataTable
  2.         'Code to load user criteria from database
  3.         Dim ordertype As String
  4.         If _status = "Online" Then
  5.             ordertype = "Online"
  6.         ElseIf _status = "Tax Cert Call" Then
  7.             ordertype = "Call"
  8.         End If
  9.  
  10.  
  11.  
  12.         Dim TaxConnStr As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & ConfigurationManager.AppSettings("Database")
  13.         Dim dbConnection As OleDbConnection = New OleDbConnection(TaxConnStr)
  14.         Try
  15.  
  16.             Dim queryString As String
  17.  
  18.             queryString = "Select Username, Amount, Rank FROM UserCriteria "
  19.             queryString += "WHERE UserCriteria.State = '" & _state & "' AND UserCriteria.County = '" & _county & "' AND UserCriteria.Status = '" & _status & "' AND UserCriteria.Client = '" & _client & "' AND UserCriteria.Department = '" & _department & "' AND UserCriteria.OrderNumber = '" & _ordernumber & "';"
  20.  
  21.  
  22.             Dim dbCommand As OleDbCommand = New OleDbCommand
  23.             dbCommand.CommandText = queryString
  24.             dbCommand.Connection = dbConnection
  25.             Dim dataAdapter As OleDbDataAdapter = New OleDbDataAdapter
  26.             dataAdapter.SelectCommand = dbCommand
  27.             Dim dataSet As DataSet = New DataSet
  28.             dataAdapter.Fill(dataSet)
  29.  
  30.  
  31.             If dataSet.Tables(0).Rows.Count >= 1 Then
  32.                 FindUserByCriteria = dataSet.Tables(0)
  33.             End If
  34.  
  35.  
  36.             Console.WriteLine(vbCrLf)
  37.             For i = 0 To FindUserByCriteria.Rows.Count - 1
  38.                 If Not IsUserOnline(FindUserByCriteria.Rows(i).Item("UserName")) Then
  39.                     FindUserByCriteria.Rows(i).Delete()
  40.                 End If
  41.             Next
  42.             FindUserByCriteria.AcceptChanges()
  43.  
  44.  
  45.         Catch ex As Exception
  46.             Console.WriteLine(ex.Message)
  47.             myLogger.Log(ex.Message)
  48.             SendMail(ex.Message)
  49.         Finally
  50.             dbConnection.Close()
  51.         End Try
  52.  
  53.     End Function
So, i get the "Object reference not set to an instance of an object." error at the
Expand|Select|Wrap|Line Numbers
  1. For i = 0 to FindUserByCriteria.rows.count - 1
line. I swear this was working for me not just 3 days ago...not sure what has changed in my code recently to make this error pop up. Any help would be nice.
May 8 '13 #1
1 1389
vijay6
158 100+
Hey maylortaylor, you don't have error in line number 32 in your code? 'FindUserByCriteria' is a method. But you're assigning a data-table to it.
May 9 '13 #2

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

Similar topics

5
by: Tommy Lang | last post by:
Why doesn't the following code work? I get an error at the following line... CardGroup.PropertyCardType = (CardType)0; The error is "Object reference not set to an instance of an object.", which...
13
by: Max | last post by:
Hi There! I'm having a mysterious error right after I login using Forms Authentication in my ASP.NET app. Below is the error... Exception Details: System.NullReferenceException: Object...
1
by: Max Gay via .NET 247 | last post by:
I am having a problem with a page that I am trying to develop. Iam new at asp.net. The page I have created makes a datagrid that has two links aedit and a cancel link. When you click either of the...
8
by: ST | last post by:
Hello everyone, Can anyone help me with this error above when I debug my web app project in vstudio.net?? I can't figure it out! It was working fine for months, and now all of a sudden it's not!!...
4
by: Ankit Aneja | last post by:
giving following error System.NullReferenceException' occurred in Additional information: Object reference not set to an instance of an object. it is breaking on line:if(cl.status==true) code...
5
by: Varangian | last post by:
ImageButton ship; ship = new ImageButton; for (int i=0; i<5; i++) { ship.ImageUrl = pathofImage; ship.ID = "ShipNo" + i.ToString(); ship.Click += new...
5
by: labelle | last post by:
this is driving me nuts, and i can't figure it out: i am creating a mapper that updates two tables at the same time, one with "ticket order" information, and the other with "ticket" information....
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...
3
by: shapper | last post by:
Hello, I have the following loop and error message: foreach (Theme theme in Profile.Collaborator.Themes) { ... And I get the following error: Object reference not set to an instance of an...
1
Markus
by: Markus | last post by:
Running a for loop to find the selected check boxes, I ran into this error This error only occurs if there are no checkboxes selected. Otherwise, it works fine. The for loop: for (int i = 0; i...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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...
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.