Hi Spider
You're very close.
As you have already worked out, when you run a plain SQL statement which uses parameters, such as
Code:
WHERE (aspnet_Users.UserName LIKE '%' + @UserName + '%')"
sql server essentially replaces the places where @UserName appears with the value you specify.
Stored procedures work slightly differently in that the parameter is passed as, well, a parameter to the stored procedure, which will itself do the replacement, in exactly the same sort of way you pass parameters to a method in
VB. There is a fairly good step by step, if slightly long-winded, introduction to stored procedures and input variables at
http://www.sql-server-performance.co...basics_p3.aspx
When the ASP.NET page calls the stored procedure, it only needs to send the name of the procedure and the values to give the parameters. So it actually runs something like
Code:
EXEC GetParticipantbyParticipantId param1Value, param2Value
So the question is how to tell the procedure what parameters to expect. To do this, you add them in a list after the name of the procedure and before the AS bit. So your one would look something like:
Code:
ALTER PROCEDURE GetParticipantbyParticipantId (
@UserName VARCHAR(20)
) AS
SELECT Participant.UserId, Participant.FirstName,
Participant.LastName, aspnet_Users.UserName FROM
Participant INNER JOIN aspnet_Users ON Participant.
UserId = aspnet_Users.UserId WHERE aspnet_Users.UserName =@UserName
RETURN
Note that putting brackets round the list is optional, but I find it helps readability.
HTH
Phil