Showing posts with label source. Show all posts
Showing posts with label source. Show all posts

Thursday, March 29, 2012

object records set HELP??

hello friends I am using actice directory as my data source through LDAP to get the usernam/password, and thn after authantication i use LDAP to get the user information (username, name, phone, email, location etc from active directory user profiles)

As u can see in the code i am using the loop to write the information on the page using

Response. write

I wan't to use some other data control to make the output more redable, like Repeater.

Sub getdetails()Dim objCommand, objConnection, strBase, strFilter, strAttributes'Declare the variables as stringDim strQuery, objRecordset, strName, strCN, strCompany, strOfficeLocation, strDept, strJobtitle, strStreetAddress, strCounty, strPostalcode, strPhone, strMail

objCommand = CreateObject(

"ADODB.Command")

objConnection = CreateObject(

"ADODB.Connection")

objConnection.Provider =

"ADsDSOObject"

objConnection.Open(

"Active Directory Provider")

objCommand.ActiveConnection = objConnection

'Define the Search Base, Filter and Attributes

strBase =

"<LDAP://dc=ESPRIT,dc=local>"

strFilter =

"(&(objectCategory=person)(objectClass=user)(sAMAccountName=" +Me.lbl_welcome.Text +"))"'database field name are same as in AD

strAttributes =

"sAMAccountName,cn,company,l,department,title,streetAddress,st,postalCode,telephonenumber,mail"'Subtree is the default base

strQuery = strBase &

";" & strFilter &";" & strAttributes &";subtree"

objCommand.CommandText = strQuery

'objCommand.Properties("Page Size") = 100'objCommand.Properties("Timeout") = 30' objectCommand_Properties(cache Results) if set to False gives some error so keep it True always

objCommand.Properties(

"Cache Results") =True

objRecordset = objCommand.Execute

'Pick the values of the fields in string variablesDoUntil objRecordset.EOF'Search the whole database Record till EOF and put the field value in the string variable and write it to the document(page)

strName = objRecordset.Fields(

"sAMAccountName").Value

strCN = objRecordset.Fields(

"cn").value

strCompany = objRecordset.Fields(

"company").value

strOfficeLocation = objRecordset.Fields(

"l").value

strDept = objRecordset.Fields(

"department").value

strJobtitle = objRecordset.Fields(

"title").value

strStreetAddress = objRecordset.Fields(

"streetAddress").value

strCounty = objRecordset.Fields(

"st").value

strPostalcode = objRecordset.Fields(

"postalCode").value

strPhone = objRecordset.Fields(

"telephonenumber").value

strMail = objRecordset.Fields(

"mail").value

Response.Write(

"User Name: " & strName &" Common Name: " & strCN &" Company Name: " & strCompany &" Office/Branch " & strOfficeLocation &" Department Name: " & strDept &" Job Title: " & strJobtitle &" Full Address: " & strStreetAddress &" County: " & strCounty &" Postal Code: " & strPostalcode &" Phone: " & strPhone &" Email: " & strMail)

objRecordset.MoveNext()

Loop

objConnection.Close()

'Connection ClosedEndSub

I am using object recordset for this. can anybdy suggest me how i can use some other datacontrol with this coding.

Thanks

You mentioned you wanted to use a repeater which is an ASP.NET control, but your code looks like Classic ASP. What are you using ASP.NET or Classic ASP?

Friday, March 16, 2012

Object reference not set to an instance of an object. - Label

I am gettign the above error. My source errors out here:

Line 11: 'check if phone is listed to the public
Line 12: 'if not listed change label to warn user
Line 13: If CType(e.Item.FindControl("UnlistedLabel"), Label).Text = "True" Then
Line 14: CType(e.Item.FindControl("lblUnlisted"), Label).Visible = True
Line 15: End If

Full Sub Code:

Protected Sub DataList1_ItemDataBound(ByVal senderAs Object,ByVal eAs DataListItemEventArgs)
'check if phone is listed to the public
'if not listed change label to warn user
If CType(e.Item.FindControl("UnlistedLabel"), Label).Text ="True"Then
CType(e.Item.FindControl("lblUnlisted"), Label).Visible =True
End If
End Sub

Why is this happening, and weirded yet, it worked about 30 times until I restarted my computer. I have read and googled lots and seems like I should be able to called directly, but perhaps I need declare my labels first?

Any help would be appreciated.

I think you may have the variable names wrong, in one instance you search for "UnlistedLabel" and in the second you search for "lblUnlisted", I assume these are meant to reference the same object?

Thanks

Amar