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

NullReferenceException - Getting the string contained in each item

Hi,
I keep getting the error " Object reference not set to an instance of an object." in relation to the line : selA = CType(lstStudents.Items(r.Index), String)

Any advice/help?

Expand|Select|Wrap|Line Numbers
  1.             Dim BRow As DataRow
  2.             Dim i As Integer
  3.             Dim selA As String
  4.             selA = CType(lstStudents.Items(r.Index), String)
  5.             BRow = objDataSet.Tables("tblStudent").Rows.Find(selA)
  6.             Do While selA <> ""
  7.                 If BRow IsNot Nothing Then
  8.                     Dim studentRows() As DataRow = BRow.Item("StudentID")
  9.                     If studentRows.Length > 0 Then
  10.                         For Each student As DataRow In studentRows
  11.                             Dim strID As Integer = student("StudentID")
  12.                             'add this item
  13.                             objCurrentRow1.Item("StudentID") = strID
  14.                         Next
  15.                     End If
  16.                 End If
  17.                 i = i + 1
  18.             Loop 
'r' has been declared earlier as
Expand|Select|Wrap|Line Numbers
  1. Dim r As MeasureItemEventArgs
Feb 7 '09 #1
1 1197
Plater
7,872 Expert 4TB
Are you sure it returns a string type for every index?
You have possibly a problem in a few places.
Looking at: selA = CType(lstStudents.Items(r.Index), String)
Is "r" always a value, or is it Nothing(null)?
Is "r.Index" always a valid number in the range of lstStudents, or does it sometimes = -1?
Does lstStudents.Items(r.Index) always produce a string type? Have you checked .GetType() to make sure its a string?
Feb 9 '09 #2

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

Similar topics

5
by: Fabio Papa | last post by:
Hi, I am fairly new to programming and and even newer to dotnet. I appoligise in advance if this is a dumb questions, and I would appreciate if you could answer it anyways. :) I am writing a...
2
by: Raed Sawalha | last post by:
i have a windows form(Main) with listview, when click an item in listview i open other window form (Sub) which generate the selected item from parent window in as treeview items when click any item...
3
by: Patrick.O.Ige | last post by:
I'm loading an Array below but getting the error "Object reference not set to an instance saying 'ItemNumber = CType(Args.Item.FindControl("ItemNumber"), TextBox).Text' is the error line. I DON'T...
5
by: Patrick.O.Ige | last post by:
What could cause the error:- System.NullReferenceException: Object reference not set to an instance of an object. Any ideas?
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
7
by: hazz | last post by:
yes i should know this but ... V,-1,1,2,-1,333,5 I would like to return the value from any position within the comma delimited string position 1 is "v" position 2 is "-1" position 6 is...
1
by: Craig | last post by:
This is killing me, I've been trying to figure this out for 2 days. When I click on the linkbutton, it executes the GetData(int) method to set the DataSource. The FAILURE is when it tries to...
1
by: Jeff | last post by:
hey asp.net 2.0 The line "e.Item.Parent.ChildItems.Remove(e.Item);" gives this error: 'e.Item' threw an exception of type 'System.NullReferenceException' System.Web.UI.WebControls.MenuItem...
1
by: firebirds98 | last post by:
Im getting a NullReferenceException when I goto add a product to my cart, i get the error when i come to this part cart.AddProduct(productnumber, name, price, prodQty, knobColor, finishColor) ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...

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.