Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 16th, 2006, 12:13 PM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default ASP.NET Stored Procedures

I'm pretty much a newbie when it comes to stored procedures and ASP.NET, but I'm wanting to convert all of my recordsets to stored procedures throughout my site. I'm running into trouble with what should be a simple stored procedure.

This is what I classically would have done using a recordset:
Code:
<%
Response.Buffer = True
'Declare form variables
Dim strUsername As Object = trim(Request.Form("txtUsername"))
Dim strPassword As Object = trim(Request.Form("txtPassword"))

'Recordset
Dim objConn As Object, rsAccounts As Object
objConn = Server.CreateObject("ADODB.Connection")
objConn.Open (strConnAccounts)
rsAccounts = "SELECT * FROM tblAccounts WHERE Username = '" & strUsername & "' AND Password = '" & strPassword & "'"
rsAccounts = objConn.Execute(rsAccounts)
objConn.Close
rsAccounts = nothing
objConn = nothing

'Test output
Response.Write("FName: " & rsAccounts("FName") & "<br />")
Response.Write("LName: " & rsAccounts("LName") & "<br />")
%>
How can I accomplish this with using a Stored Procedure? I don't understand how I can use variables within an ASP.NET page within a Stored Procedure's WHERE clause. Thanks for any help.

KWilliams
 
Old March 16th, 2006, 11:56 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Well, first you need to learn some fundamentals of sql. If you have sql server installed, look into the help which is called Books On Line. You can also get a beginners book on sql. The best way to learn is just to try.
You stored procedure can look something just like your select statement:

Create Procedure MyProcedure
@Username varchar(30),
@Password varchar(10)
As

Select *
From tblAccounts
Where UserName = @UserName


Then you can use the sqldataadapter(.NET 1.0 and 1.1) to call the sp. Just specify it when you go throgh the wizard. You can slso do it through code.
If you are using VS2005(.NET 2.0) then you can use the sqldatasource object.

Hope this gets you started...

Jim





Similar Threads
Thread Thread Starter Forum Replies Last Post
asp and ms sql stored procedures solomon_13000 Classic ASP Basics 1 July 11th, 2005 12:04 AM
CR.Net and Stored Procedures eman2a Crystal Reports 1 September 2nd, 2004 11:32 PM
trigger stored procedures from asp Kornel Classic ASP Databases 7 July 15th, 2004 10:47 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.