ASP question

troyavitia
troyavitia used Ask the Experts™
on
Hi,

Can anyone help me out with this. I have an ASP script(below) that will query and return the requested data. The

problem is I need to Insert this data into a SQL table.

I guess my problem is the object type and the methods available. I cannot use <%= Ouser.("cn") %> and must use

<%=oUsr.cn%>

Thanks Troy
********************************************************
On Error Resume Next

Dim oCon, oCom, oRec
Dim oUsr,

Set oCon = CreateObject("ADODB.Connection")
Set oCom = CreateObject("ADODB.Command")

oCon.Provider = "ADsDSOObject"
oCon.Open "Active Directory Provider"
oCom.ActiveConnection = oCon
oCom.CommandText = "<LDAP://ldap.server.com:398/o=server.com>;(|(mail=troy_avitia@yahoo.com));ADsPath"

Set oRec = oCom.Execute
Set oUsr = GetObject(oRec.Fields("ADsPath").Value)
 
       
     
 <div align="left" style="width: 602; height: 206">
 <form method="POST" action="data_entry.asp" >
 <b><a href="data_search.asp"><font size="2"> width="100%">
 
 
 <tr>
     <td width="24%"><b>Name:</b></td>
     <td width="76%"><%=oUsr.cn%> &nbsp;</td>
   </tr>
   <tr>
     <td width="24%"><b>Email:</b></td>
     <td width="76%"><%=oUsr.preferredMail%>&nbsp;</td>
   </tr>
   <tr>
     <td width="24%"><b>Phone:</b></td>
     <td width="76%"><%=oUsr.telephoneNumber%> &nbsp;</td>
   </tr>


oRec.Close
oCon.Close

Set oRec = Nothing
Set oCom = Nothing
Set oCon = Nothing
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2013

Commented:
????

Why would you title a Question ASP question , and then not post it in the ASP topic area?  Do you not want the top ASP experts to help you with it?

Cd&
Why don' you use hidden fields?

You could do something like

create hidden field

ex.   <input type="hidden" name="hName" value="<%= oUsr.cn %>">

And in het data_entry.asp file you can retrieve the hidden field value with:

request.form("hName")

and persist the data there

I hope this helps...

WVDK
On Error Resume Next

Dim oCon, oCom, oRec
Dim oUsr,

Set oCon = CreateObject("ADODB.Connection")
Set oCom = CreateObject("ADODB.Command")

oCon.Provider = "ADsDSOObject"
oCon.Open "Active Directory Provider"
oCom.ActiveConnection = oCon
oCom.CommandText = "<LDAP://ldap.server.com:398/o=server.com>;(|(mail=troy_avitia@yahoo.com));ADsPath"

Set oRec = oCom.Execute
Set oUsr = GetObject(oRec.Fields("ADsPath").Value)

oRec.Close
oCon.Close

oCon.Provider = MSDAORA or whatever      
oCon.Open your connection string
oCom.ActiveConnection = oCon
oCom.CommandText = "INSERT INTO yourtable (name, email, phone) VALUES ('" & oUsr.cn & "', '" & oUsr.preferredMail "', '" & oUsr.telephoneNumber " & "')"
Set oRec = oCom.Execute

Set oRec = Nothing
Set oCom = Nothing
Set oCon = Nothing
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Commented:
Joe's solution should work...

Author

Commented:
Let me try to ask it this way using the code below, I get the following error.

ADODB.Recordset error '800a0cc1'
Item cannot be found in the collection corresponding to the requested name or ordinal.
/tsetldapeb.asp, line 29




******************************************************
<html>
<head>
</head>
<body>
<%
   set oConn = Server.CreateObject("ADODB.Connection")
   set oCommand = Server.CreateObject("ADODB.Command")
   set oRS = Server.CreateObject("ADODB.Recordset")

   oConn.Provider = "ADsDSOObject"
   oConn.Open "Ads Provider"

   set oCommand.ActiveConnection = oConn  'set the active connection
   strQuery= "<LDAP://ldap.yahoo.com:384/o=yahoo.com>;(|(mail=troy.avitia@yahoo.com));ADsPath"
   oCommand.CommandText = strQuery

   set oRS = oCommand.Execute   'Execute the query
   %>  
   <TABLE BORDER=3>
   <TR bgcolor="#C0C0C0">
      <TH><b>Display Name</b></th>
      <TR>    
     <TD> <%=oRS.fields("cn")%>
      <font color="#FF0000">
   </font>
&nbsp;</td>
   </tr>
   </TABLE>
   <br><br>
</table>
</BODY>
</HTML>
Don't you have to tell it what fields you want to return?
Try...
strQuery= "<LDAP://ldap.yahoo.com:384/o=yahoo.com>;(|(mail=troy.avitia@yahoo.com));cn;ADsPath"

Author

Commented:
Well heres what I ended up using;

<%

'Dim the email submit from ldap_search.asp page
strEmail = request.form("mail")

Dim oCon, oCom, oRec, oUsr
Dim Name
Dim Email
Dim Phone
Dim Street
Dim City
Dim MailStop
Dim State
Dim Country
Dim PostalCode
Dim Org
Dim BusUnit

'Connection information
Set oCon = CreateObject("ADODB.Connection")
Set oCom = CreateObject("ADODB.Command")

'this code was provided by the Ed team and seems to be VB code
oCon.Provider = "ADsDSOObject"
oCon.Open
oCom.ActiveConnection = oCon
oCom.CommandText = "<LDAP://ldap.corp.com:389/o=corp.com>;(|(mail=" & strEmail & "));ADsPath"

Set oRec = oCom.Execute
Set oUsr = GetObject(oRec("ADsPath"))

'this was added to convert the vb code to ADO compliiant code and make it availbe to use late in the email and database entry page
Name = oUsr.cn
Email = oUsr.preferredMail
Phone = oUsr.telephoneNumber
Street = oUsr.street
City = oUsr.l
MailStop = oUsr.mailStop
State = oUsr.st
Country = oUsr.co
PostalCode = oUsr.postalcode
Org = oUsr.OrganizationChart
BusUnit = oUsr.BusinessGroup



%>  

</font>
 <div align="left" style="width: 602; height: 206">
 <form method="post" action="ldap_entry.asp">


 <b><a href="gartner_search.asp"><font size="2">No, this is not me</font><br></a></b></p>
 
 
 <input type="hidden" name="Name" value="<% = (Name) %>" </td>
 <input type="hidden" name="Email" value="<% = (Email) %>" </td>
 <input type="hidden" name="Phone" value="<% = (Phone) %>" </td>
 <input type="hidden" name="Street" value="<% = (Street) %>" </td>
 <input type="hidden" name="City" value="<% = (City) %>" </td>
 <input type="hidden" name="Mailstop" value="<% = (Mailstop) %>" </td>
 <input type="hidden" name="State" value="<% = (state) %>" </td>
 <input type="hidden" name="Country" value="<% = (Country) %>" </td>
 <input type="hidden" name="Postalcode" value="<% = (PostalCode) %>" </td>
 <input type="hidden" name="Org" value="<% = (Org) %>" </td>
 <input type="hidden" name="BusUnit" value="<% = (BusUnit) %>" </td>

 
 <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#000000" width="100%">
 
 
 <tr>
     <td width="24%"><b>Name:</b></td>
     <td width="76%"><%=(name)%> &nbsp;</td>
   </tr>
   <tr>
     <td width="24%"><b>Email:</b></td>
     <td width="76%"><%=(email)%>&nbsp;</td>
   </tr>
   <tr>
     <td width="24%"><b>Phone:</b></td>
     <td width="76%"><%=(phone)%> &nbsp;</td>
   </tr>
   <tr>

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial