Hi,
I have an interview tomorrow eeeekk. It is for a ASP developer role. I have been coding in JAVA and Oracle the last few years so been dusting the ASP and SQL server cobwebs away!
There is going to be some sort of technical interview on calling stored procedures from ASP. Here is my practice. Any comments would be good. If there is anything I could do better.
ASP page :-
Stored Proc:-
Ok so it is mega basic but its a start LOL!
I have an interview tomorrow eeeekk. It is for a ASP developer role. I have been coding in JAVA and Oracle the last few years so been dusting the ASP and SQL server cobwebs away!
There is going to be some sort of technical interview on calling stored procedures from ASP. Here is my practice. Any comments would be good. If there is anything I could do better.
ASP page :-
Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%Option Explicit%>
<html>
<head>
<title>Stored Procedure Example</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<%
' Create ADO constants
Const adcmd = 4
Const adInteger = 3
Const adParamInput = 1
' Create variables
Dim con
Dim cmd
Dim rs, rs2
Dim paramId
Dim dropDownAValue, dropDownBValue, formSubmittedValue
' Gets the form submission values from the request object
dropDownAValue = Request.Form("dropDownA")
dropDownBValue = Request.Form("dropDownB")
formSubmittedValue = Request.Form("formSubmitted")
' Create conection object
Set con = Server.CreateObject("ADODB.Connection")
' Open the connection providing DNSless conection details
con.Open "Provider=SQLOLEDB;Data Source=pc1\sqlexpress;" _
& "Initial Catalog=drctestdb;User Id=sa;Password=xxxxxx;" _
& "Connect Timeout=15;Network Library=dbmssocn;"
'Create the command object
Set cmd = Server.CreateObject("ADODB.Command")
' Relate the command to the connection
cmd.ActiveConnection = con
cmd.CommandText = "GetDropDownOptions"
cmd.CommandType = adcmd
' Set the input parameter
Set paramId = cmd.CreateParameter("@Id", adInteger, adParamInput)
paramId.Value = "1"
cmd.Parameters.Append paramId
' Execute the command storing the results in the recordset
Set rs = CreateObject("ADODB.Recordset")
Set rs = cmd.Execute
' Clear the parameter so the stored procedure can be reused on this page. Loop required for multiple input perameters.
cmd.Parameters.Delete 0
' Set the input parameter
Set paramId = cmd.CreateParameter("@Id", adInteger, adParamInput)
paramId.Value = "2"
cmd.Parameters.Append paramId
' Execute the command storing the results in the recordset
Set rs2 = CreateObject("ADODB.Recordset")
Set rs2 = cmd.Execute
' Clear objects that are finished with
Set paramId = Nothing
Set cmd = Nothing
%>
<body>
<form action="test.asp" method="post" enctype="application/x-www-form-urlencoded" name="dropDownTestForm">
<select name="dropDownA">
<%
' Loop through the result set outputting the values
While Not rs.EOF
%>
<option><%Response.Write Trim(rs.Fields("drop_down_option"))%></option>
<%
rs.MoveNext
Wend
%>
</select>
<select name="dropDownB">
<%
' Loop through the result set outputting the values
While Not rs2.EOF
%>
<option><%Response.Write Trim(rs2.Fields("drop_down_option"))%></option>
<%
rs2.MoveNext
Wend
%>
</select>
<input type="hidden" name="formSubmitted" value="true">
<input name="dropDownTestFormSubmit" type="submit" value="Submit">
</form>
<%
'Display the selections if the form has been submitted.
If lcase(formSubmittedValue) = "true" then
%>
<table border="0" cellpadding="0">
<tr>
<td>Drop down A value :</td>
<td><%=dropDownAValue%></td>
</tr>
<tr>
<td>Drop down B value :</td>
<td><%=dropDownBValue%></td>
</tr>
</table>
<%end if%>
</body>
</html>
<%
' Close the connection and destroy remaining variables and objects
con.Close
Set con = Nothing
Set rs = Nothing
Set rs2 = Nothing
Set dropDownAValue = Nothing
Set dropDownBValue = Nothing
Set formSubmittedValue = Nothing
%>
Stored Proc:-
Code:
CREATE PROCEDURE [dbo].[GetDropDownOptions]
@Id int
AS
SELECT drop_down_option
FROM drop_down_test
WHERE id = @Id
Ok so it is mega basic but its a start LOL!
Last edited: