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

Error... Object reference not set ???

Can someone please tell me why I keep getting the following error! And how do
I resolve the problem???

Thanks

System.NullReferenceException: Object reference not set to an instance of an
object.

Dim src As DirectorySearcher = New
DirectorySearcher("(&(objectCategory=Person)(objec tClass=user))")
createTable()
src.SearchRoot = de
src.SearchScope = SearchScope.Subtree
For Each res As SearchResult In src.FindAll
Dim topRow As DataRow = ds.Tables("users").NewRow
topRow("Name") = res.Properties("sn")(0)
ds.Tables("users").Rows.Add(topRow)
Next
DataGrid1.DataSource = ds.Tables("users")
DataGrid1.DataBind()
Nov 19 '05 #1
3 1435
Where does the error occur? Looking at the code either de is nothing or
Table("users") is nothing.
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:E4**********************************@microsof t.com...
Can someone please tell me why I keep getting the following error! And how
do
I resolve the problem???

Thanks

System.NullReferenceException: Object reference not set to an instance of
an
object.

Dim src As DirectorySearcher = New
DirectorySearcher("(&(objectCategory=Person)(objec tClass=user))")
createTable()
src.SearchRoot = de
src.SearchScope = SearchScope.Subtree
For Each res As SearchResult In src.FindAll
Dim topRow As DataRow = ds.Tables("users").NewRow
topRow("Name") = res.Properties("sn")(0)
ds.Tables("users").Rows.Add(topRow)
Next
DataGrid1.DataSource = ds.Tables("users")
DataGrid1.DataBind()

Nov 19 '05 #2
sn might equal nothing in some cases!

Do I need to put in some kind of error capture statement???

If so how would I write it???

Perhaps something LIKE this???

Thanks for the response!

Dim src As DirectorySearcher = New
DirectorySearcher("(&(objectCategory=Person)(objec tClass=user))")
createTable()
src.SearchRoot = de
src.SearchScope = SearchScope.Subtree
For Each res As SearchResult In src.FindAll
If res.Properties("sn")(0) is Nothing then
response.write ("Null")
Else
Dim topRow As DataRow = ds.Tables("users").NewRow
topRow("Name") = res.Properties("sn")(0)
ds.Tables("users").Rows.Add(topRow)
End If
Next
DataGrid1.DataSource = ds.Tables("users")
DataGrid1.DataBind()


"Joseph Byrns" wrote:
Where does the error occur? Looking at the code either de is nothing or
Table("users") is nothing.
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:E4**********************************@microsof t.com...
Can someone please tell me why I keep getting the following error! And how
do
I resolve the problem???

Thanks

System.NullReferenceException: Object reference not set to an instance of
an
object.

Dim src As DirectorySearcher = New
DirectorySearcher("(&(objectCategory=Person)(objec tClass=user))")
createTable()
src.SearchRoot = de
src.SearchScope = SearchScope.Subtree
For Each res As SearchResult In src.FindAll
Dim topRow As DataRow = ds.Tables("users").NewRow
topRow("Name") = res.Properties("sn")(0)
ds.Tables("users").Rows.Add(topRow)
Next
DataGrid1.DataSource = ds.Tables("users")
DataGrid1.DataBind()


Nov 19 '05 #3
That might well give you an out of range type exception aswell, you should
probably try something like:

If res.Properties("sn").Count > 0 Then
If res.Properties("sn")(0) is Nothing then
response.write ("Null")
Else
Dim topRow As DataRow = ds.Tables("users").NewRow
topRow("Name") = res.Properties("sn")(0)
ds.Tables("users").Rows.Add(topRow)
End If
endif

"Tim::.." <myatix_at_hotmail.com> wrote in message
news:48**********************************@microsof t.com...
sn might equal nothing in some cases!

Do I need to put in some kind of error capture statement???

If so how would I write it???

Perhaps something LIKE this???

Thanks for the response!

Dim src As DirectorySearcher = New
DirectorySearcher("(&(objectCategory=Person)(objec tClass=user))")
createTable()
src.SearchRoot = de
src.SearchScope = SearchScope.Subtree
For Each res As SearchResult In src.FindAll
If res.Properties("sn")(0) is Nothing then
response.write ("Null")
Else
Dim topRow As DataRow = ds.Tables("users").NewRow
topRow("Name") = res.Properties("sn")(0)
ds.Tables("users").Rows.Add(topRow)
End If
Next
DataGrid1.DataSource = ds.Tables("users")
DataGrid1.DataBind()


"Joseph Byrns" wrote:
Where does the error occur? Looking at the code either de is nothing or
Table("users") is nothing.
"Tim::.." <myatix_at_hotmail.com> wrote in message
news:E4**********************************@microsof t.com...
> Can someone please tell me why I keep getting the following error! And
> how
> do
> I resolve the problem???
>
> Thanks
>
> System.NullReferenceException: Object reference not set to an instance
> of
> an
> object.
>
> Dim src As DirectorySearcher = New
> DirectorySearcher("(&(objectCategory=Person)(objec tClass=user))")
> createTable()
> src.SearchRoot = de
> src.SearchScope = SearchScope.Subtree
> For Each res As SearchResult In src.FindAll
> Dim topRow As DataRow = ds.Tables("users").NewRow
> topRow("Name") = res.Properties("sn")(0)
> ds.Tables("users").Rows.Add(topRow)
> Next
> DataGrid1.DataSource = ds.Tables("users")
> DataGrid1.DataBind()


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Ike | last post by:
Anyone knows what cuases this under 6.0 ? -Ike
0
by: sks_cpp | last post by:
I am trying to wrap the map iterator for keys and values. However, I seem to run into problems with the values for const_iterator - it works for all other combinations. Below I list my code and...
5
by: xuatla | last post by:
Hi, I encountered the following compile error of c++ and hope to get your help. test2.cpp: In member function `CTest CTest::operator+=(CTest&)': test2.cpp:79: error: no match for 'operator='...
2
by: Gregory | last post by:
Hi, One of the disadvantages of using error handling with error codes instead of exception handling is that error codes retuned from a function can be forgotten to check thus leading to...
1
by: Martine | last post by:
Hi there! I have a problem with programmatically adding user controls to my mobile webforms. If I load my usercontrol programmatically (in the Page_Load), the object is instantiated, I have...
6
by: blash | last post by:
Can someone help me? I really don't have a clue. My company staff told me they often got such error: "Object reference not set to an instance of an object." when they are in search result 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...
15
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the...
4
by: rushikesh.joshi | last post by:
Hi All, I have created my own WebControl and want to add it in my aspx page at runtime. it's compiling perfectly, but when i m going to execute, it gives me error of "Object reference not set...
4
by: Cylix | last post by:
Sample code of the problem: function inputOne() { alert('a'); } <input name="inputOne" id="inputOne" value="Warn" onclick="inputOne()"> The error is the object doesn't support this method.
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
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?
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
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
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
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,...

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.