ADSI Guru... HELP!

G

Guest

Hi can someone please help!

I have been having issues with the following piece of code! Everytime I run
the application I get:

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

Source Error:


Line 70: topRow(" ") = "<img src='../images/user.gif'>"
Line 71:
Line 72: If res.Properties("sn").Count > 0 Then
Line 73: If res.Properties("sn")(0) Is Nothing Then
Line 74: Response.Write("Null")

I think this is because the value of "SN" in some records is null or
nothing! Can someone please help!

Thanks


Dim src As DirectorySearcher = New
DirectorySearcher("(&(objectCategory=Person)(objectClass=user))")
createTable()
src.SearchRoot = de
src.SearchScope = SearchScope.Subtree
For Each res As SearchResult In src.FindAll


Dim topRow As DataRow = ds.Tables("contacts").NewRow
topRow("&nbsp;") = "<img src='../images/user.gif'>"

If res.Properties("sn").Count > 0 Then
If res.Properties("sn")(0) Is Nothing Then
Response.Write("Null")
Else
topRow("Name") = res.Properties("sn")(0)
'topRow("Dept.") =
res.Properties("physicalDeliveryOfficeName")(0)
'topRow("Ext") = res.Properties("telephoneNumber")(0)
'topRow("Email") = res.Properties("mail")(0)

End If
End If

ds.Tables("contacts").Rows.Add(topRow)


Next
DataGrid1.DataSource = ds.Tables("contacts")
DataGrid1.DataBind()

End Sub
 
G

Guest

Don't worry I managed to fix it!



If res.Properties.Contains("physicalDeliveryOfficeName") Then
topRow("Dept.") =
CStr(res.Properties("physicalDeliveryOfficeName")(0))
Else
topRow("Dept.") = ""
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top