Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

asp,gettin stuff from database, sql

  • 19-07-2007 03:12PM
    #1
    Registered Users, Registered Users 2 Posts: 36


    i have code to add to a database and thats grand, now i what to say that it as been successfully added, any ideas? i tryed this:

    =========================

    <% dim newVar = Recordset1.Source("select BuildingName from tblBuilding where BuildingID = <%=(Recordset1_last)%>")
    Response.Write("You have added " + newVar + "to the database")
    %>

    =========================
    it adds to the end of database so i tryed to use "Recordset1_last" which displays the id successfully.
    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 706 ✭✭✭DJB


    It can be difficult to get the very last id but if you try as follows:

    sConn = "" 'your connection string
    sSQL = "SELECT TOP 1 FROM tblBuilding ORDER BY BuildingID DESC"

    SET rs = Server.CreateObject("ADODB.recordset")
    rs.Open sSQL, sConn

    response.write "You have added " & rs("some_column") & " to the database".


    or why not just do a response.write that the user was successful?


  • Registered Users, Registered Users 2 Posts: 36 or89


    i think your right it would save so much time just puttin in it was successful, thanks for the help


  • Registered Users, Registered Users 2 Posts: 273 ✭✭stipey


    If I understand you correctly....
    Dim conn
    Dim sqlString
    
    set conn = Server.CreateObject("ADODB.Connection")
    conn.open connectionString
    
    sqlString = "insert into myTable values (1, 'Robert', 'Zimmerman') 
    
    [B][I][COLOR="Green"]' Use conn.execute to run the insert - since no recordset is returned.[/COLOR][/I][/B]
    conn.execute sqlString
    
    [COLOR="Green"][B][I]' Now check the connection's error collection[/I][/B][/COLOR]
    if conn.Errors.Count = 0 then
      Response.Write "Everything is tickety-boo"
    else
    
      for each e in conn.Errors
      [B][I][COLOR="Green"]  ' sometimes an error will be returned with an error number of 0
        ' this is just an information message so we can ignore it.[/COLOR][/I][/B]
        if e.Number <> 0 then
          Response.Write "Error Number: " & e.Number & "<br>"
        end if
      next
    end if
    

    Of course best practice would be to put the insert/update into a stored proc that either returns a recordset or has at least one output parameter and then create a parameters collection in your asp to pass the values to the database.

    Disclaimer: All code is, at best, an approximation.


Advertisement