How to select and insert using asp

M

MrHelpMe

Hello experts,

O.k I give up on this. I have an LDAP query from asp working
correctly. It is returning data fine. Now I need to know how to take
this data and then submitt it into the database. Can this be done in
one page and is there any other way to do this without putting a submit
button on a page. Almost like a file that I can pass to the user and
he can click it to insert into a database. My way of do it is to
simply to put a submit button on the page and when the user hits submit
the values selected will go to the database. However the only thing on
this page is a submit(kinda useless).

This is part of my code
Code:
<form name="form1" method="post" action="ldap_second.asp">

<TABLE BORDER = 2>
<TR><TD>Name</TD>
<TD>Mail</TD>
<TD>GivenName</TD>
<TD>Address</TD>
</TR>

<%
Do Until objRecordSet.EOF%>
<%
Dim N
Dim M
Dim GN
N = objRecordset("Name")
M = objRecordset("Mail")
GN = objRecordset("GivenName")
SA = objRecordset("StreetAddress")

response.write "<TR>"
response.write "<TD>" & N & "</TD>"
response.write "<TD>" & M & "</TD>"
response.write "<TD>" & GN & "</TD>"
response.write "<TD>" & SA & "</TD>"
response.write "</TR>"
%>
<%      objRecordSet.MoveNext
Loop
%>
</TABLE>
<p><input type="submit" value="Submit" name="B1</p>

Now on my ldap_second how to I take the values and submit them to a
database. Your help is appreciated.
 
M

Mike Brind

MrHelpMe said:
Hello experts,

O.k I give up on this. I have an LDAP query from asp working
correctly. It is returning data fine. Now I need to know how to take
this data and then submitt it into the database. Can this be done in
one page and is there any other way to do this without putting a submit
button on a page. Almost like a file that I can pass to the user and
he can click it to insert into a database. My way of do it is to
simply to put a submit button on the page and when the user hits submit
the values selected will go to the database. However the only thing on
this page is a submit(kinda useless).

This is part of my code
Code:
<form name="form1" method="post" action="ldap_second.asp">

<TABLE BORDER = 2>
<TR><TD>Name</TD>
<TD>Mail</TD>
<TD>GivenName</TD>
<TD>Address</TD>
</TR>

<%
Do Until objRecordSet.EOF%>
<%
Dim N
Dim M
Dim GN
N = objRecordset("Name")
M = objRecordset("Mail")
GN = objRecordset("GivenName")
SA = objRecordset("StreetAddress")

response.write "<TR>"
response.write "<TD>" & N & "</TD>"
response.write "<TD>" & M & "</TD>"
response.write "<TD>" & GN & "</TD>"
response.write "<TD>" & SA & "</TD>"
response.write "</TR>"
%>
<%      objRecordSet.MoveNext
Loop
%>
</TABLE>
<p><input type="submit" value="Submit" name="B1</p>

Now on my ldap_second how to I take the values and submit them to a
database. Your help is appreciated.

Well, given that a form requires fields to be of any use (as you alluded to)
why not simply response.write the values into hidden form fields?
 
M

MrHelpMe

Mike thanks for the reply. Anyway you could show me how to do that
with some sample code? Sorry still learning everything:)



Mike said:
MrHelpMe said:
Hello experts,

O.k I give up on this. I have an LDAP query from asp working
correctly. It is returning data fine. Now I need to know how to take
this data and then submitt it into the database. Can this be done in
one page and is there any other way to do this without putting a submit
button on a page. Almost like a file that I can pass to the user and
he can click it to insert into a database. My way of do it is to
simply to put a submit button on the page and when the user hits submit
the values selected will go to the database. However the only thing on
this page is a submit(kinda useless).

This is part of my code
Code:
<form name="form1" method="post" action="ldap_second.asp">

<TABLE BORDER = 2>
<TR><TD>Name</TD>
<TD>Mail</TD>
<TD>GivenName</TD>
<TD>Address</TD>
</TR>

<%
Do Until objRecordSet.EOF%>
<%
Dim N
Dim M
Dim GN
N = objRecordset("Name")
M = objRecordset("Mail")
GN = objRecordset("GivenName")
SA = objRecordset("StreetAddress")

response.write "<TR>"
response.write "<TD>" & N & "</TD>"
response.write "<TD>" & M & "</TD>"
response.write "<TD>" & GN & "</TD>"
response.write "<TD>" & SA & "</TD>"
response.write "</TR>"
%>
<%      objRecordSet.MoveNext
Loop
%>
</TABLE>
<p><input type="submit" value="Submit" name="B1</p>

Now on my ldap_second how to I take the values and submit them to a
database. Your help is appreciated.

Well, given that a form requires fields to be of any use (as you alluded to)
why not simply response.write the values into hidden form fields?
 
M

Mike Brind

Do it in the same way as you've written the table out using response.write.

Response.Write "<input type=""hidden""... etc

--
Mike Brind

MrHelpMe said:
Mike thanks for the reply. Anyway you could show me how to do that
with some sample code? Sorry still learning everything:)



Mike said:
MrHelpMe said:
Hello experts,

O.k I give up on this. I have an LDAP query from asp working
correctly. It is returning data fine. Now I need to know how to take
this data and then submitt it into the database. Can this be done in
one page and is there any other way to do this without putting a submit
button on a page. Almost like a file that I can pass to the user and
he can click it to insert into a database. My way of do it is to
simply to put a submit button on the page and when the user hits submit
the values selected will go to the database. However the only thing on
this page is a submit(kinda useless).

This is part of my code
Code:
<form name="form1" method="post" action="ldap_second.asp">

<TABLE BORDER = 2>
<TR><TD>Name</TD>
<TD>Mail</TD>
<TD>GivenName</TD>
<TD>Address</TD>
</TR>

<%
Do Until objRecordSet.EOF%>
<%
Dim N
Dim M
Dim GN
N = objRecordset("Name")
M = objRecordset("Mail")
GN = objRecordset("GivenName")
SA = objRecordset("StreetAddress")

response.write "<TR>"
response.write "<TD>" & N & "</TD>"
response.write "<TD>" & M & "</TD>"
response.write "<TD>" & GN & "</TD>"
response.write "<TD>" & SA & "</TD>"
response.write "</TR>"
%>
<%      objRecordSet.MoveNext
Loop
%>
</TABLE>
<p><input type="submit" value="Submit" name="B1</p>

Now on my ldap_second how to I take the values and submit them to a
database. Your help is appreciated.

Well, given that a form requires fields to be of any use (as you alluded
to)
why not simply response.write the values into hidden form fields?
 
M

MrHelpMe

Thanks again Mike,

So now I got it working and the hidden variables are being passed over.
The code is as follows:
Code:
Dim oConn
Dim sSQL
Dim N
Dim M
Dim GN
Dim SA
Dim objRS

N=Request.Form("Name")
M=Request.Form("Email")
GN=Request.Form("GivenName")
SA=Request.Form("StreetAddress")


Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open ("connection")
'set ObjRS = server.CreateObject ("ADODB.Recordset")

If Request.Form("SubmitButton") = "Submit" Then

Do While Not ObjRS.EOF

sSQL = "INSERT into Tablex (Name, Mail, GName,PostalCode)"
sSQL = sSQL &  "VALUES ('" & N&"', '"& M&"', '" & GN&"', '" &
SA&"')"
oConn.Execute ssql

ObjRS.MoveNext
Loop
ObjRS.close
set ObjRS = nothing
oConn.close
set oConn = nothing
End If
%>

However, now I am receiving error:
Code:
Error Type:
ADODB.Recordset (0x800A0E78)
Operation is not allowed when the object is closed.
/activedirectory/ldap_second.asp, line 22

Any ideas? Thanks.






Mike said:
Do it in the same way as you've written the table out using response.write.

Response.Write "<input type=""hidden""... etc

--
Mike Brind

MrHelpMe said:
Mike thanks for the reply. Anyway you could show me how to do that
with some sample code? Sorry still learning everything:)



Mike said:
Hello experts,

O.k I give up on this. I have an LDAP query from asp working
correctly. It is returning data fine. Now I need to know how to take
this data and then submitt it into the database. Can this be done in
one page and is there any other way to do this without putting a submit
button on a page. Almost like a file that I can pass to the user and
he can click it to insert into a database. My way of do it is to
simply to put a submit button on the page and when the user hits submit
the values selected will go to the database. However the only thing on
this page is a submit(kinda useless).

This is part of my code
Code:
<form name="form1" method="post" action="ldap_second.asp">

<TABLE BORDER = 2>
<TR><TD>Name</TD>
<TD>Mail</TD>
<TD>GivenName</TD>
<TD>Address</TD>
</TR>

<%
Do Until objRecordSet.EOF%>
<%
Dim N
Dim M
Dim GN
N = objRecordset("Name")
M = objRecordset("Mail")
GN = objRecordset("GivenName")
SA = objRecordset("StreetAddress")

response.write "<TR>"
response.write "<TD>" & N & "</TD>"
response.write "<TD>" & M & "</TD>"
response.write "<TD>" & GN & "</TD>"
response.write "<TD>" & SA & "</TD>"
response.write "</TR>"
%>
<%      objRecordSet.MoveNext
Loop
%>
</TABLE>
<p><input type="submit" value="Submit" name="B1</p>

Now on my ldap_second how to I take the values and submit them to a
database. Your help is appreciated.


Well, given that a form requires fields to be of any use (as you alluded
to)
why not simply response.write the values into hidden form fields?
 
L

Larry Bud

MrHelpMe said:
Thanks again Mike,

So now I got it working and the hidden variables are being passed over.
The code is as follows:
Code:
Dim oConn
Dim sSQL
Dim N
Dim M
Dim GN
Dim SA
Dim objRS

N=Request.Form("Name")
M=Request.Form("Email")
GN=Request.Form("GivenName")
SA=Request.Form("StreetAddress")


Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open ("connection")
'set ObjRS = server.CreateObject ("ADODB.Recordset")

If Request.Form("SubmitButton") = "Submit" Then

Do While Not ObjRS.EOF

sSQL = "INSERT into Tablex (Name, Mail, GName,PostalCode)"
sSQL = sSQL &  "VALUES ('" & N&"', '"& M&"', '" & GN&"', '" &
SA&"')"
oConn.Execute ssql

ObjRS.MoveNext
Loop
ObjRS.close
set ObjRS = nothing
oConn.close
set oConn = nothing
End If
%>

However, now I am receiving error:
Code:
Error Type:
ADODB.Recordset (0x800A0E78)
Operation is not allowed when the object is closed.
/activedirectory/ldap_second.asp, line 22

Any ideas? Thanks.

The insert is a one time deal. There's no reason to be looping through
it, as there's nothing to loop through (it's an INSERT, not a select).

The error is from "Do While Not ObjRS.EOF" because ObjRS has not been
opened.
 
M

MrHelpMe

I see. Thanks Larry for the response.


Larry said:
MrHelpMe said:
Thanks again Mike,

So now I got it working and the hidden variables are being passed over.
The code is as follows:
Code:
Dim oConn
Dim sSQL
Dim N
Dim M
Dim GN
Dim SA
Dim objRS

N=Request.Form("Name")
M=Request.Form("Email")
GN=Request.Form("GivenName")
SA=Request.Form("StreetAddress")


Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open ("connection")
'set ObjRS = server.CreateObject ("ADODB.Recordset")

If Request.Form("SubmitButton") = "Submit" Then

Do While Not ObjRS.EOF

sSQL = "INSERT into Tablex (Name, Mail, GName,PostalCode)"
sSQL = sSQL &  "VALUES ('" & N&"', '"& M&"', '" & GN&"', '" &
SA&"')"
oConn.Execute ssql

ObjRS.MoveNext
Loop
ObjRS.close
set ObjRS = nothing
oConn.close
set oConn = nothing
End If
%>

However, now I am receiving error:
Code:
Error Type:
ADODB.Recordset (0x800A0E78)
Operation is not allowed when the object is closed.
/activedirectory/ldap_second.asp, line 22

Any ideas? Thanks.

The insert is a one time deal. There's no reason to be looping through
it, as there's nothing to loop through (it's an INSERT, not a select).

The error is from "Do While Not ObjRS.EOF" because ObjRS has not been
opened.
 

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

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,701
Latest member
XavierQ83

Latest Threads

Top