ClioSport.net

Register a free account today to become a member!
Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

  • When you purchase through links on our site, we may earn an affiliate commission. Read more here.

ASP + SQL server guru's



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 :-
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:
This job will lead to .net

It is a bit of a backwards step to take some forward steps if that makes sense!

I haven't got any .net experiance as I have been doing JSP/Servlets and JAVA for the last few years. I want to do .net but the prereq for this job is being able to do classic ASP.
 
  Audi TT 225
Classis ASP is very easy and your code looks good.
ASP's a just a basic script lanuage theres not much to it when you compare it to a full blown lanuage. You will need to forget everything you know about classic ASP before you get into .Net trust me lol
Your Java experience should help you out tho.
Good luck :D
 
Yeah the JAVA stuff I have done is fairly advanced. I understand that .net is far more along the lines of MVC and OO paradigms just like the JAVA servlets and JSPs are. I look forward to it if I can land a job! A few JAVA ones in the pipeline as well but I am going for some .net experience rather than chasing the money at this stage.

Cheers for the luck :)

with all the fancy visual studio stuff ms has come up with the .net should write itself anyway I would just sit there looking at clio sport! ;) Jokes!
 
  Audi TT 225
No jokes mate thats what I do, Ive designed my system so well it runs its self pretty much! I work at home, takes me no time to change my code and rebuild it, xbox 360 and work on my car the rest of the time ;)
 


Top