troyavitia
asked on
ASP question
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.Connec tion")
Set oCom = CreateObject("ADODB.Comman d")
oCon.Provider = "ADsDSOObject"
oCon.Open "Active Directory Provider"
oCom.ActiveConnection = oCon
oCom.CommandText = "<LDAP://ldap.server.com:3 98/o=serve r.com>;(|( mail=troy_ avitia@yah oo.com));A DsPath"
Set oRec = oCom.Execute
Set oUsr = GetObject(oRec.Fields("ADs Path").Val ue)
<div align="left" style="width: 602; height: 206">
<form method="POST" action="data_entry.asp" >
<b><a href="data_search.asp"><fo nt size="2"> width="100%">
<tr>
<td width="24%"><b>Name:</b></ td>
<td width="76%"><%=oUsr.cn%> </td>
</tr>
<tr>
<td width="24%"><b>Email:</b>< /td>
<td width="76%"><%=oUsr.prefer redMail%>& nbsp;</td>
</tr>
<tr>
<td width="24%"><b>Phone:</b>< /td>
<td width="76%"><%=oUsr.teleph oneNumber% > </td>
</tr>
oRec.Close
oCon.Close
Set oRec = Nothing
Set oCom = Nothing
Set oCon = Nothing
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.Connec
Set oCom = CreateObject("ADODB.Comman
oCon.Provider = "ADsDSOObject"
oCon.Open "Active Directory Provider"
oCom.ActiveConnection = oCon
oCom.CommandText = "<LDAP://ldap.server.com:3
Set oRec = oCom.Execute
Set oUsr = GetObject(oRec.Fields("ADs
<div align="left" style="width: 602; height: 206">
<form method="POST" action="data_entry.asp" >
<b><a href="data_search.asp"><fo
<tr>
<td width="24%"><b>Name:</b></
<td width="76%"><%=oUsr.cn%> </td>
</tr>
<tr>
<td width="24%"><b>Email:</b><
<td width="76%"><%=oUsr.prefer
</tr>
<tr>
<td width="24%"><b>Phone:</b><
<td width="76%"><%=oUsr.teleph
</tr>
oRec.Close
oCon.Close
Set oRec = Nothing
Set oCom = Nothing
Set oCon = Nothing
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
On Error Resume Next
Dim oCon, oCom, oRec
Dim oUsr,
Set oCon = CreateObject("ADODB.Connec tion")
Set oCom = CreateObject("ADODB.Comman d")
oCon.Provider = "ADsDSOObject"
oCon.Open "Active Directory Provider"
oCom.ActiveConnection = oCon
oCom.CommandText = "<LDAP://ldap.server.com:3 98/o=serve r.com>;(|( mail=troy_ avitia@yah oo.com));A DsPath"
Set oRec = oCom.Execute
Set oUsr = GetObject(oRec.Fields("ADs Path").Val ue)
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
Dim oCon, oCom, oRec
Dim oUsr,
Set oCon = CreateObject("ADODB.Connec
Set oCom = CreateObject("ADODB.Comman
oCon.Provider = "ADsDSOObject"
oCon.Open "Active Directory Provider"
oCom.ActiveConnection = oCon
oCom.CommandText = "<LDAP://ldap.server.com:3
Set oRec = oCom.Execute
Set oUsr = GetObject(oRec.Fields("ADs
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
Joe's solution should work...
ASKER
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 .Connectio n")
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:38 4/o=yahoo. com>;(|(ma il=troy.av itia@yahoo .com));ADs Path"
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>
</td>
</tr>
</TABLE>
<br><br>
</table>
</BODY>
</HTML>
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
set oCommand = Server.CreateObject("ADODB
set oRS = Server.CreateObject("ADODB
oConn.Provider = "ADsDSOObject"
oConn.Open "Ads Provider"
set oCommand.ActiveConnection = oConn 'set the active connection
strQuery= "<LDAP://ldap.yahoo.com:38
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>
</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:38 4/o=yahoo. com>;(|(ma il=troy.av itia@yahoo .com));cn; ADsPath"
Try...
strQuery= "<LDAP://ldap.yahoo.com:38
ASKER
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.Connec tion")
Set oCom = CreateObject("ADODB.Comman d")
'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.co m>;(|(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)%> </td>
</tr>
<tr>
<td width="24%"><b>Email:</b>< /td>
<td width="76%"><%=(email)%>&n bsp;</td>
</tr>
<tr>
<td width="24%"><b>Phone:</b>< /td>
<td width="76%"><%=(phone)%> </td>
</tr>
<tr>
<%
'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.Connec
Set oCom = CreateObject("ADODB.Comman
'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
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">
<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 width="76%"><%=(name)%> </td>
</tr>
<tr>
<td width="24%"><b>Email:</b><
<td width="76%"><%=(email)%>&n
</tr>
<tr>
<td width="24%"><b>Phone:</b><
<td width="76%"><%=(phone)%> </td>
</tr>
<tr>
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&