Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

asp,gettin stuff from database, sql

Options
  • 19-07-2007 3:12pm
    #1
    Registered Users 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 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 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 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