SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Function to confirm successful database entry?

    Hi guys,

    I have a string of ASP code that writes a new database entry into my SQL server table. Is there a function that I can run directly after the database entry code, that can tell me if the data was successfully entered?

    Eg of current code:

    SQLCode = "INSERT INTO GarProductList VALUES (" & "'" & App_Name & "'" & ", " & "'" & Option_Number & "'" & ")"
    response.write "SQL Code is: " & SQLCode & "<br>"
    Set objRS = MyConn.Execute (SQLCode)

    << perhaps call certain function here to verify SQL table was updated? >>

    If database update successful -> function should return 1
    If database update fails -> function should return 0 ... or something like that. In any case, some exception response should be returned.

  2. #2
    SitePoint Enthusiast hombre_de_las_ca's Avatar
    Join Date
    Apr 2005
    Location
    Bangalore, India
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    create a recordset of the table and do as follows.
    Code:
    objrs.movelast
    if objrs.fields(" GarProductList").value = your_value Then
    response.write "<body onLoad= "%>"alert('Process Complete!');">
    <%
    else
    response.write "<body onLoad= "%>"alert('Process Not Complete!');"
    <%
    end if%>
    this way it would give a pop up giving the result!!!
    tell me if it works!!!
    CaveMan
    Don't ask what your Country can do for you,
    Ask what you can do for your Country.

  3. #3
    SitePoint Enthusiast hombre_de_las_ca's Avatar
    Join Date
    Apr 2005
    Location
    Bangalore, India
    Posts
    90
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lightbulb

    or even better
    <%
    if your_expression then
    whatever = "Sucess!!!"
    else
    whatever = "Try Again!!!"
    %>
    <script language="JavaScript">
    function Mothers_day ()
    {
    alert("<%= whatever %>");
    }
    </script>
    now call the script from the body tag by the onload event.
    Don't ask what your Country can do for you,
    Ask what you can do for your Country.

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    I would use this:

    Code:
    <%
    on error resume next
    
    	Dim Connection
    	Set Connection = Server.CreateObject("ADODB.Connection")
    		Connection.Open "testdsn"
    		
    	Dim Recordset
    	Set Recordset = Server.CreateObject("ADODB.Recordset")
    		Recordset.Open "SELECT * FROM Table", Connection, 2, 2
    		
    		IF Request.Querystring("action") = "Insert" THEN
    		
    			Recordset.addnew
    			Recordset("Field1") = Request.Form("Field1")
    			Recordset("Field2") = Request.Form("Field2")
    			Recordset("Field3") = Request.Form("Field3")
    			Recordset.update
    			Recordset.Close
    			
    			Recordset.Open "SELECT * FROM Table WHERE Field1 = '" & Request.Form("Field1") & "' AND Field2 = '" & Request.Form("Field2") & "'", Connection, 2, 2
    			
    			IF Recordset.EOF THEN
    			
    				Recordset.Close
    			Set Recordset = Nothing
    				Connection.Close
    			Set Connection = Nothing
    			redirect_string = "?error=Insert_Failed"
    
    				For each item in Request.Form	
    										redirect_string = redirect_string & "&" & item & "=" & request.form(item)
    					
    				Loop
    			
    				Response.Redirect "insert_page.asp" & redirect_string
    				
    			else
    			
    					Success_id = Recordset("ID")
    					
    					Recordset.Close
    				Set Recordset = Nothing
    					Connection.Close
    				Set Connection = Nothing
    				
    					response.redirect "successfulinsert.asp?ID=" & Success_id
    					
    			end if
    			
    			
    		END IF
    %>
    Hasn't been tested, but what this should do, is first try to insert what you want to insert, then call it back using the form data that was meant to be inserted, if it doesn't find a record, then it will redirect back the page that sent it with the form data in querystrings, so you can call the info into those field for editting.

    If it is successful, then it will redirect to a success page with a insert id, in which you can either review the entered information, or push comes to shove you can remove the id from the response.redirect and get it to show a success message.

    Apart from that?

    What else can you ask for?

    Gav

  5. #5
    SitePoint Addict
    Join Date
    Jun 2001
    Location
    Malaysia
    Posts
    352
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a bunch guys... the code looks good! Will give it a shot as soon as I get the chance


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •