I am currently trying to figure out how to use a stored procedure that will return the result of a count query, and I am having some trouble.
Here is the stored procedure:
CREATE PROCEDURE qryVerifyUser
@user_mail varchar(15),
@user_password varchar(15),
@user_count int output
AS
SELECT @user_count =( SELECT Count(*) from new_user
where user_mail=@user_mail
and user_password=@user_password)
GO
The object is to pass the login info from a form and return the count as an int. The code for the aspx page looks like this:
<script language="c#" runat="server">
void Page_Load(){
if (Page.IsPostBack){
if (Request.Form["Email.Text"] != ""
{
SqlConnection aConnection = new SqlConnection
(
System.Configuration.ConfigurationSettings.AppSettings.Get("SurfJob"
);
SqlCommand aCommand = new SqlCommand();
aCommand.CommandText = "dbo.[qryVerifyUser]";
aCommand.CommandType = System.Data.CommandType.StoredProcedure;
aCommand.Parameters.Add(new SqlParameter("@user_mail", Request.Form["Email"]));
aCommand.Parameters.Add(new SqlParameter("@user_password", Request.Form["Password"]));
aCommand.Parameters.Add(new SqlParameter("@user_count", 1));
aConnection.Open();
aCommand.Connection = aConnection;
aCommand.ExecuteReader();
Response.Write("__" + aCommand.Parameters["@user_count"].Value);
aConnection.Close();
The last add new parameter is the @user_count, but it doesn't return the value from the query. It only retruns the initial value. If I remove the initial value, the code fails. I have seen a bunch of code that sets up a parameter as a return value, but none of the examples I have tried work.
please help.
Jim
Here is the stored procedure:
CREATE PROCEDURE qryVerifyUser
@user_mail varchar(15),
@user_password varchar(15),
@user_count int output
AS
SELECT @user_count =( SELECT Count(*) from new_user
where user_mail=@user_mail
and user_password=@user_password)
GO
The object is to pass the login info from a form and return the count as an int. The code for the aspx page looks like this:
<script language="c#" runat="server">
void Page_Load(){
if (Page.IsPostBack){
if (Request.Form["Email.Text"] != ""
SqlConnection aConnection = new SqlConnection
(
System.Configuration.ConfigurationSettings.AppSettings.Get("SurfJob"
);
SqlCommand aCommand = new SqlCommand();
aCommand.CommandText = "dbo.[qryVerifyUser]";
aCommand.CommandType = System.Data.CommandType.StoredProcedure;
aCommand.Parameters.Add(new SqlParameter("@user_mail", Request.Form["Email"]));
aCommand.Parameters.Add(new SqlParameter("@user_password", Request.Form["Password"]));
aCommand.Parameters.Add(new SqlParameter("@user_count", 1));
aConnection.Open();
aCommand.Connection = aConnection;
aCommand.ExecuteReader();
Response.Write("__" + aCommand.Parameters["@user_count"].Value);
aConnection.Close();
The last add new parameter is the @user_count, but it doesn't return the value from the query. It only retruns the initial value. If I remove the initial value, the code fails. I have seen a bunch of code that sets up a parameter as a return value, but none of the examples I have tried work.
please help.
Jim