Showing posts with label records. Show all posts
Showing posts with label records. 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?

Monday, March 26, 2012

Object Reference Not Set to an Instance of an Object

I'm having a problem updating records in a datagrid. I'm using template columns for the columns to be edited so I can have drop down lists in them. Heres an example of what a column might look like:

<asp:TemplateColumn>
<HeaderTemplate>
<DIV align="center">Hours</DIV>
</HeaderTemplate>
<ItemTemplate>
<DIV align="center"><%# Container.DataItem("Hrs") %></DIV>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddldgHours" runat="server">
<asp:ListItem Value="4.00">4.00</asp:ListItem>
<asp:ListItem Value="3.00">3.00</asp:ListItem>
<asp:ListItem Value="2.00">2.00</asp:ListItem>
<asp:ListItem Value="1.00">1.00</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>

I click on the edit command in the datagrid and this control displays fine, however whenever I click on the update command I receive an error 'Object reference not set to an instance to an object'. Does anyone have any suggestions? I can provide more code if necessary. Thanks.Hi,
If u are using code-behind, then u have to define the dropdownlist inside ur code-behind before using it.
i would like you to post the exact error that u are having, with some code, to know which is generating the error,

best of luck.
THIS IS THE SPECIFIC ERROR:


Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

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


THIS IS MY CODE FROM THE METHOD WHERE THE ERROR OCCURS:

'Visual Aspect of Page
pnl1.Visible = False
pnl2.Visible = False
pnl3.Visible = True
pnl4.Visible = False

'THE NEXT LINE CAUSES THE ERROR
transcript.UpdateCourse(dgTranscript.DataKeys(e.Item.ItemIndex), _
GenerateIdentity(), _
txtdgCourseId.Text, _
txtdgTitle.Text, _
ddldgGrade.SelectedValue, _
ddldgHours.SelectedValue)

txtCourseID.Text = Nothing
txtCourseTitle.Text = Nothing
dgTranscript.EditItemIndex = -1

DisplayTranscript()


To get the value of ddldgGrade, you have to do something like this in the Update event handler:

strGrade = ((DropDownList)e.Item.FindControl("ddldgGrade")).SelectedValue;

I think that this is the syntax. I don't have all my good code with me, since I'm at work. The idea is that first you have to use the FindControl method of the DataGridItem class. Then you have to cast it to the correct class, which I'm guessing is DropDownList. Then, if you put parentheses around that, you can access the whole thing as one expression, and you can get the SelectedValue from that.

You can do the same thing with the TextBox. I'm sure you can take it from here. If you need more help, drop a line.
hello, the problem as i see it is from the "ddldgGrade" what is that a dropdownlist ? if yes, u have to initialize a dropdownlist in ur server-side code !!!! and try to use

ddldgGRade.SelectedItem.Text instead !!!!

hope these help
Combining the above metods worked best for me. I created a dropdownlist in my code and set it equal to "e.Item.FindControl("ddldgGrade")". Thanks for the help.