Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 30th, 2004, 09:59 AM
Authorized User
 
Join Date: Jun 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default Cannot Insert into listbox

I have created an asp page which is used to insert new contract numbers to the list box. I am not sure what I am doing wrong in this code. The table name is correct and so are the fields. Am I missing something? Here is the code. Thank you

Function addContract()
    ' Add Contract
    set rs = server.CreateObject("adodb.recordset")
    SQL = "select * from tblJPAContracts where wasdcontractno = '" & strContractNo & "'"
    ' Run Query
    rs.open sql, cn, 0, 3

    ' Check to see if contract exists
    If rs.eof Then
        ' Contract does not exist, add new record
        With rs
            .addnew
            .Fields("wasdcontractno") = strContractNo
                .update
                .close
        End With
    Else
        ' adding process
        ' Contract already exists, display error message
        'Response.Write "Error: Contract " & strContractNo & " already exists!"
    End If
    set rs = nothing
End Function

Any suggestions I would greatly appreciate.

slypunk
__________________
slypunk
 
Old August 30th, 2004, 09:23 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello,

Are you getting any error?


  Make sure where are you opening the connection and did you specify the ADO constants? and also sure that where you are calling the function.




 
Old August 30th, 2004, 09:34 PM
Authorized User
 
Join Date: Aug 2004
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think the recordset opened is not writeable.
use Rs.supports("Addnew") to check.
set the cursor type to dynamic, by default type is Forward-only and read-only.

 
Old August 31st, 2004, 08:02 AM
Authorized User
 
Join Date: Jun 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by rajanikrishna
 Hello,

Are you getting any error?


Make sure where are you opening the connection and did you specify the ADO constants? and also sure that where you are calling the function.




It does not give me an error at all. In fact, it does nothing at all when I hit the add button. Let me be more specific on my code by showing you exactly what I did:

' --- FUNCTIONS STARTS BELOW

Function addContract()
    ' Add Contract
    set rs = server.CreateObject("adodb.recordset")
    SQL = "select * from tblJPAContracts where wasdcontractno = '" & strContractNo & "'"
    ' Run Query
    rs.open sql, cn, 0, 3

    ' Check to see if contract exists
    If rs.eof Then
        ' Contract does not exist, add new record
        With rs
        .addnew
        .Fields("wasdcontractno") = strContractNo
            '.Fields("dateentered") = now
            .update
            .close
        End With
      Else
        End If
    set rs = nothing
End Function

Function deleteContract()
set rs = server.CreateObject("adodb.recordset")
    SQL = "select * from tblJPAContracts where wasdcontractno = '" & strContractNo & "'"
    ' Run Query
    rs.open sql, cn, 0, 3
    ' Check to see if contract exists
    If not rs.eof Then
        ' deletes record
        With rs
            .delete
            .movenext
            .close
        End With
    Else
    End If
    set rs = nothing
End Function

Function searchContract()
    ' Search for a contract
    Set rs = SearchContractNo(strContractNo)
    ' Check for end of file (eof)
    if rs.EOF then
        'same as below
        'response.write "<script language=javascript>alert('contract Number Not Found');</script>"
        %>
        <script language=javascript>
            alert("Contract Number Not Found");
        </script>
        <%
    else
        wasdcontractno = rs("wasdcontractno")
    end if
end function

' --- PROCESSING LOGIC STARTS BELOW

Dim strContractNo, rs, wasdcontractno, btnAction

strContractNo = request("searchvalue")

' Process the Add/Update/Delete/Search functions
btnAction = request("btnAction")

'TESTmp
'response.write "TEST3 " & strContractNo
'response.end

select case btnAction
    case "Add"
        ' Add the contract
        if strContractNo <> "" then ' Make sure user entered a value
            addContract()
            ' After the add, perform a search to reload contract :)
            searchContract
        end if
    case "Delete"
        'Delete the contract
        if strContractNo <> "" then
            deleteContract()
        end if
    case ""
        ' Process the search
        if strContractNo <> "" then
            searchContract
        end if
end select

I hope this information helps. :D Thanks

slypunk
 
Old August 31st, 2004, 09:41 PM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default



  I didnt find any error in your code except the opening connection(cn). But you said that you are not getting any error.

And also,

  In the function AddContract, if rs is not EOF you will defly get error coz you are releasing the resources without closing the recordset. And after executing the addContract function you are calling the searchContract function.


' Search for a contract
    Set rs = SearchContractNo(strContractNo)
    ' Check for end of file (eof)
    if rs.EOF then
        'same as below
        'response.write "<script language=javascript>alert('contract Number Not Found');</script>"
        %>
        <script language=javascript>
            alert("Contract Number Not Found");
        </script>
        <%
    else



Do you have any statement like on error resume next in the code?



 
Old September 1st, 2004, 01:01 PM
Authorized User
 
Join Date: Jun 2003
Posts: 98
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by rajanikrishna



I didnt find any error in your code except the opening connection(cn). But you said that you are not getting any error.

Exactly reason is because it is coming from another .asp file

And also,

In the function AddContract, if rs is not EOF you will defly get error coz you are releasing the resources without closing the recordset. And after executing the addContract function you are calling the searchContract function.


' Search for a contract
    Set rs = SearchContractNo(strContractNo)
    ' Check for end of file (eof)
    if rs.EOF then
        'same as below
        'response.write "<script language=javascript>alert('contract Number Not Found');</script>"
        %>
        <script language=javascript>
            alert("Contract Number Not Found");
        </script>
        <%
    else



Do you have any statement like on error resume next in the code?



No I do not but wouldn't that skip the error and not function correctly? What is the best way to rework my way around this code to make it work? Thanks

slypunk
 
Old September 2nd, 2004, 02:23 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default



  Or else you do like this,



   ...
    if rs.EOF then
       strQry="INSERT INTO tablename(fld1,fld2) VALUES(" & val1 & "," & val2 & ")"

    conn.execute strQry
    end if
   ...







Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple Listbox values in another listbox terryv Excel VBA 0 June 27th, 2007 07:01 AM
Listbox sarah lee ASP.NET 2.0 Basics 2 May 15th, 2007 02:09 PM
Listbox problem when insert or update hcanales ASP.NET 1.x and 2.0 Application Design 1 September 21st, 2006 02:53 PM
trigger to insert current date on insert kev_79 SQL Server 2000 3 January 23rd, 2006 05:58 PM
I'm back :) Listbox var from listbox MichaelTJ .NET Web Services 2 October 21st, 2003 07:06 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.