How to select and insert using asp

Discussion in 'ASP General' started by MrHelpMe, Oct 25, 2006.

  1. MrHelpMe

    MrHelpMe Guest

    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.
     
    MrHelpMe, Oct 25, 2006
    #1
    1. Advertising

  2. MrHelpMe

    Mike Brind Guest

    "MrHelpMe" <> wrote in message
    news:...
    > 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?

    --
    Mike Brind
     
    Mike Brind, Oct 25, 2006
    #2
    1. Advertising

  3. MrHelpMe

    MrHelpMe Guest

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



    Mike Brind wrote:
    > "MrHelpMe" <> wrote in message
    > news:...
    > > 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?
    >
    > --
    > Mike Brind
     
    MrHelpMe, Oct 25, 2006
    #3
  4. MrHelpMe

    Mike Brind Guest

    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" <> wrote in message
    news:...
    > Mike thanks for the reply. Anyway you could show me how to do that
    > with some sample code? Sorry still learning everything:)
    >
    >
    >
    > Mike Brind wrote:
    >> "MrHelpMe" <> wrote in message
    >> news:...
    >> > 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?
    >>
    >> --
    >> Mike Brind

    >
     
    Mike Brind, Oct 25, 2006
    #4
  5. MrHelpMe

    MrHelpMe Guest

    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 Brind wrote:
    > 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" <> wrote in message
    > news:...
    > > Mike thanks for the reply. Anyway you could show me how to do that
    > > with some sample code? Sorry still learning everything:)
    > >
    > >
    > >
    > > Mike Brind wrote:
    > >> "MrHelpMe" <> wrote in message
    > >> news:...
    > >> > 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?
    > >>
    > >> --
    > >> Mike Brind

    > >
     
    MrHelpMe, Oct 26, 2006
    #5
  6. MrHelpMe

    Larry Bud Guest

    MrHelpMe wrote:
    > 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.
     
    Larry Bud, Oct 26, 2006
    #6
  7. MrHelpMe

    MrHelpMe Guest

    I see. Thanks Larry for the response.


    Larry Bud wrote:
    > MrHelpMe wrote:
    > > 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.
     
    MrHelpMe, Oct 26, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?RGFiYmxlcg==?=

    select gridview row without using select button?

    =?Utf-8?B?RGFiYmxlcg==?=, Mar 3, 2006, in forum: ASP .Net
    Replies:
    5
    Views:
    101,635
    dch31969
    Feb 27, 2009
  2. Replies:
    1
    Views:
    1,873
    Albert Hopkins
    Dec 6, 2008
  3. Feege
    Replies:
    0
    Views:
    502
    Feege
    Dec 20, 2005
  4. palmiere
    Replies:
    1
    Views:
    471
    Erwin Moller
    Feb 9, 2004
  5. Bonge Boo!
    Replies:
    5
    Views:
    230
    Bonge Boo!
    Apr 25, 2005
Loading...

Share This Page