| | |
How to change into stored Procedure
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2005
Posts: 54
Reputation:
Solved Threads: 0
Dear friends:
I've copy the asp.net code from Unleashed book. I want to use this part of the code to take stored procedure rather than select statment. The stored procedure I write for is this:
*********************************************************
CREATE PROCEDURE authenticatedUser
(
@userName Varchar ( 20 ) ,
@userStatus Varchar (20),
@userPassword Varchar(20),
@jobTitle Varchar(20) Output,
@projectId Varchar(20) Output
)
AS
select projectId, jobTitle
From amcduser
where userName = @userName and userPassword = @userPassword and userStatus = "Active"
GO
*********************************************************
When the Login button is cliked the next event handler (from Asp.Net Unleashed book) will be executed. But I want to use my stored procedure instead of select statment.
How can I do that dear friends.
************************************************************
Sub button_Click(ByVal s As Object, ByVal e As EventArgs)
Dim dstEmployees As DataSet
Dim conNorthwind As SqlConnection ' Object
Dim dadEmployees As SqlDataAdapter ' no object
Dim arrvalues(1) As Object
Dim dvwEmployees As DataView
Dim intEmployeesIndex As Integer
'Get chached Dataview
dvwEmployees = Cache("amdcuser")
If dvwEmployees Is Nothing Then
dstEmployees = New DataSet()
conNorthwind = New SqlConnection("server=(local);database= childdatabase ;Trusted_Connection=yes")
dadEmployees = New SqlDataAdapter("select * From amcduser", conNorthwind)
dadEmployees.Fill(dstEmployees, "amdcuser")
dvwEmployees = dstEmployees.Tables("amdcuser").DefaultView()
dvwEmployees.Sort = "userName , userPassword"
Cache("amdcuser") = dvwEmployees
End If
'Find The Employee
arrvalues(0) = txtusername.Text
arrvalues(1) = txtpassword.Text
intEmployeesIndex = dvwEmployees.Find(arrvalues)
If intEmployeesIndex <> -1 Then
lbltest.Text = txtusername.Text & " , " & txtpassword.Text
Session("jobtitle") = dvwEmployees(intEmployeesIndex).Row("jobTitle")
Session("projectid") = dvwEmployees(intEmployeesIndex).Row("projectId")
lbltest.Text = Session("jobtitle") & "<>"
lbltest.Text &= Session("projectid")
Else
test.Text = "Employee Not Found"
End If
End Sub
*********************************************************
Regards,
Ben
I've copy the asp.net code from Unleashed book. I want to use this part of the code to take stored procedure rather than select statment. The stored procedure I write for is this:
*********************************************************
CREATE PROCEDURE authenticatedUser
(
@userName Varchar ( 20 ) ,
@userStatus Varchar (20),
@userPassword Varchar(20),
@jobTitle Varchar(20) Output,
@projectId Varchar(20) Output
)
AS
select projectId, jobTitle
From amcduser
where userName = @userName and userPassword = @userPassword and userStatus = "Active"
GO
*********************************************************
When the Login button is cliked the next event handler (from Asp.Net Unleashed book) will be executed. But I want to use my stored procedure instead of select statment.
How can I do that dear friends.
************************************************************
Sub button_Click(ByVal s As Object, ByVal e As EventArgs)
Dim dstEmployees As DataSet
Dim conNorthwind As SqlConnection ' Object
Dim dadEmployees As SqlDataAdapter ' no object
Dim arrvalues(1) As Object
Dim dvwEmployees As DataView
Dim intEmployeesIndex As Integer
'Get chached Dataview
dvwEmployees = Cache("amdcuser")
If dvwEmployees Is Nothing Then
dstEmployees = New DataSet()
conNorthwind = New SqlConnection("server=(local);database= childdatabase ;Trusted_Connection=yes")
dadEmployees = New SqlDataAdapter("select * From amcduser", conNorthwind)
dadEmployees.Fill(dstEmployees, "amdcuser")
dvwEmployees = dstEmployees.Tables("amdcuser").DefaultView()
dvwEmployees.Sort = "userName , userPassword"
Cache("amdcuser") = dvwEmployees
End If
'Find The Employee
arrvalues(0) = txtusername.Text
arrvalues(1) = txtpassword.Text
intEmployeesIndex = dvwEmployees.Find(arrvalues)
If intEmployeesIndex <> -1 Then
lbltest.Text = txtusername.Text & " , " & txtpassword.Text
Session("jobtitle") = dvwEmployees(intEmployeesIndex).Row("jobTitle")
Session("projectid") = dvwEmployees(intEmployeesIndex).Row("projectId")
lbltest.Text = Session("jobtitle") & "<>"
lbltest.Text &= Session("projectid")
Else
test.Text = "Employee Not Found"
End If
End Sub
*********************************************************
Regards,
Ben
You have to make a SqlCommand object, and change the CommandType to "CommandType.StoredProcedure". Then when you initialize the SqlDataAdapter, you pass that SqlCommand to the SqlDataAdapter.
I just found this pretty good code snippet, from this site:
The example is in C#, but it illustrates how you'd use the SqlCommand instead of just feeding a string to the SqlDataAdapter.
I just found this pretty good code snippet, from this site:
ASP.NET Syntax (Toggle Plain Text)
sqlConnection = new SqlConnection( "Integrated Security=yes;Initial Catalog=Northwind;Data Source=(local)" ); //pass the stored proc name and SqlConnection sqlCommand = new SqlCommand( "Employee Sales by Country", sqlConnection ); //important to set this as StoredProcedure is *not* the default sqlCommand.CommandType = CommandType.StoredProcedure; //instantiate SqlAdapter and DataSet sqlDataAdapter = new SqlDataAdapter( sqlCommand );
The example is in C#, but it illustrates how you'd use the SqlCommand instead of just feeding a string to the SqlDataAdapter.
Last edited by alc6379; Dec 26th, 2007 at 9:49 am. Reason: make it look nicer
Alex Cavnar, aka alc6379
![]() |
Similar Threads
- how to retrieve next unused number from table (MS SQL)
- Can return a Stored Procedure Recordset (MS SQL)
- Help with a stored procedure (MS SQL)
- how do I run a "disconnected" stored procedure (MS SQL)
- ASP.net/Stored Proc & Login Verification (ASP.NET)
- Simple ASP.Net Login Page (Using VB.Net) (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: How a doc file can be open inside browser without prompting the download dialog box
- Next Thread: Response.redirect() conflict
| Thread Tools | Search this Thread |
.net activexcontrol advice ajax alltypeofvideos appliances asp asp.net bc30451 beginner bottomasp.net box browser button c# cac checkbox click commonfunctions control css dataaccesslayer database datagridview datagridviewcheckbox datalist deadlock deployment development dgv dialog dropdownlist dynamic dynamically edit embeddingactivexcontrol expose fileuploader fill findcontrol flash formatdecimal formview gridview gudi iframe iis javascript listbox login microsoft mono mouse mssql multistepregistration news novell numerical objects opera panelmasterpagebuttoncontrols radio redirect registration relationaldatabases reportemail rotatepage save schoolproject search security sessionvariables silverlight smartcard smoobjects software sql-server sqlserver2005 ssl suse textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visualstudio web webapplications webdevelopemnt webdevelopment webprogramming webservice xsl youareanotmemberofthedebuggerusers






