Advertisement

09.17.2008 at 09:56AM PDT, ID: 23739421
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.7

Execution of SQL insert statement from ASP results in two records being inserted

Asked by HarpuaFSB in Active Server Pages (ASP), MS SQL Server

Tags:

I am really at a loss for this one, been banging my head on my desk for hours now.

Anyway, I have a page written in classic ASP that is attempting to insert a record into a table into a SQL table.

The table structure is as follows (at least as much as needs to be known for this problem):
VP_SDA
SDAID int (identity)
VoyageID nvarchar 20
DPID int
ViewByCountry smallint
CountryID nvarchar 2
[To] nvarchar 500

The ASP code is below.  I've pared it down considerably to the point where I got the code as whittled down as possible while still creating this error.

The problem is whenever a user hits submit, two identical records are inserted.

For the life of me I can't figure out why...

(test.asp?mode=create)Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
<% @ language = "vbscript" %>
<!-- #include file=library/dbconnection.asp -->
<%
	Response.Expires = -1
	Response.Buffer = True
 
	Server.ScriptTimeout = 120	
	
	Set rsSystem = Server.CreateObject("ADODB.Recordset")
	Set rsLookUp = Server.CreateObject("ADODB.Recordset")
	Set rsStowage = Server.CreateObject("ADODB.Recordset")
 
	sMode = Trim(LCase(Request.QueryString("mode")))
	
	If sMode = "create" Then
		'Record validation
	End If
	
	If sMode = "add" Then
		If Request.Form("fromsubmit") = "" Then CloseObjects : Response.Redirect "/vp_new/reports/criteria/surveyordischargeappointments.asp"
		sTo = Trim(Request.Form("to"))
		
		sSQL = "SET NOCOUNT ON"
		sSQL = sSQL & ";"
		sSQL = sSQL & "INSERT INTO VP_SDA "
		sSQL = sSQL & "("
		sSQL = sSQL & "VoyageID, "
		sSQL = sSQL & "DPID, "
		sSQL = sSQL & "ViewByCountry, "
		sSQL = sSQL & "CountryID, "
		sSQL = sSQL & "[To], "
		sSQL = sSQL & "UpdatedDateTime, "
		sSQL = sSQL & "CreatedDateTime"
		sSQL = sSQL & ") VALUES ("
		sSQL = sSQL & "'999999', "
		sSQL = sSQL & "99, "
		sSQL = sSQL & "0, "
		sSQL = sSQL & "NULL, "
		sSQL = sSQL & "'" & sTo & "', "
		sSQL = sSQL & "GETDATE(), "
		sSQL = sSQL & "GETDATE()"
		sSQL = sSQL & ")"
		sSQL = sSQL & ";"
		sSQL = sSQL & "SELECT @@IDENTITY SDAID"
		sSQL = sSQL & ";"
		Set rsSystem = objCn.Execute(sSQL)
		sSDAID = rsSystem("SDAID") & "-" & Trim(sVoyageID) & "-" & iDPID
		CloseObjects
		Session("error_type") = "confirmation"
		Session("error_message") = "Successful add"	
		Response.Redirect "test.asp?mode=view&sdaid=" & sSDAID		
	End If
%>
<html>
<head>
	<title></title>
</head>
<body>
<script language="javascript" type="text/javascript">
<!--
	function create_sda()
	{
		if (confirm("Are you sure you want to create this surveyor discharge appointment?"))
		{
			document.forms.createsda.action += "?mode=add";
			document.forms.createsda.submit();
		}
		else
			{ return false; }
	}
//-->
</script>
<div id="container">
	<div id="content">
        <div id="menu">
       	</div>
        <%	If Session("error_type") <> "" Then %>
        		<ul id="alerts">
        <%
					Response.Write "<li class=""" & Session("error_type") & """>" & Session("error_message") & "</li>"
		%>
        		</ul>
		<%	End If %> 
        <br />
        <%	If sMode = "create" Then %>
                <form name="createsda" method="post" action="test.asp" onSubmit="return create_sda();">
                    <input type="hidden" name="fromsubmit" value="true" />
                    <table class="form fourcolumn">
                    	<tr>
                            <th>To</th>
                            <td colspan="3"><textarea name="to" class="larger">Test</textarea></td>
                        </tr>
                    </table>  
                    <br />     
                    <p class="buttons">
                       	<span class="right"><input type="image" src="/vp_new/_assets/img/buttons/submit.gif" name="submit" id="submit" alt="" /></span>
                    </p>   
                </form>
      	<%	End If %>            
 	</div>
</div>
</body>
</html>
<%
	Session.Contents.Remove("error_type") 
	Session.Contents.Remove("error_message")
	
	CloseObjects
	
	Private Sub CloseObjects()
		If rsStowage.State = 1 Then rsStowage.Close
		Set rsStowage = Nothing
		If rsLookUp.State = 1 Then rsLookUp.Close
		Set rsLookUp = Nothing
		If rsSystem.State = 1 Then rsSystem.Close
		Set rsSystem = Nothing
		objCn.Close
		Set objCn = Nothing		
	End Sub
%>
[+][-]09.17.2008 at 10:01AM PDT, ID: 22501000

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.17.2008 at 10:05AM PDT, ID: 22501037

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.17.2008 at 10:08AM PDT, ID: 22501066

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.17.2008 at 10:30AM PDT, ID: 22501325

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.17.2008 at 11:11AM PDT, ID: 22501816

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.17.2008 at 11:17AM PDT, ID: 22501894

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.17.2008 at 11:21AM PDT, ID: 22501946

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.17.2008 at 11:22AM PDT, ID: 22501955

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.17.2008 at 11:24AM PDT, ID: 22501973

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]09.17.2008 at 11:27AM PDT, ID: 22502017

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Active Server Pages (ASP), MS SQL Server
Tags: ASP, SQL Server
Sign Up Now!
Solution Provided By: hielo
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-43 - Hierarchy / EE_QW_2_20070628