sqlhelper output parameter
i am working on SQLHelper class. and how to get @Email value ????????
protected void Button1_Click(object sender, EventArgs e)
{
try
{
bl.user_id = TextBox1.Text;
DataTable dt= bl.forget();
if (dt.Rows.Count != 0)
{
Response.Write( dt.Rows[0]["@Email"].ToString());
}
}
catch (Exception g)
{
Response.Write(g.Message);
}
}
Bll part.......
DataSet ds = SqlHelper.ExecuteDataset(bl.str, CommandType.StoredProcedure,
"forFetPasswo",ne开发者_如何学Cw SqlParameter("@Email", bl.user_id));
DataTable dt = new DataTable();
if (ds.Tables.Count != 0)
{
dt = ds.Tables[0];
}
return dt;
sql part.......
Alter PROCEDURE Abc
@Email nvarchar(100)output
AS
BEGIN
if (@Email !=null)
begin
if exists(select * from UserLogin where Emailid =@Email )
begin
select @Email ='mail send'
end
end
else
begin
select @Email='invalid email id'
end
END
GO
You are returning an output parameter but not handling it in the .net code. You are looking for a dataset.
The quick fix is to add select @Email AS email
to your stored proc at the end
Otherwise, change new SqlParameter
to another overload that uses direction
In your stored procedure you only assign the @Email variable, you should add something like that to the end of stored procedure
select @Email as Email
And access it in code
Response.Write( dt.Rows[0]["Email"].ToString());
And remove output
parameter ;)
In Your Case use Either User DataSet or Output parameter... Since You Are Returning Only One Value....use Output Parameter.
var param=new SqlParameter("@Email",SqlDBType.VarChar,100).Direction=ParameterDirection.Output;
SqlHelper.ExecuteNonQuery(con,Abc,param);
var Email=param.Value.toString();
Also in SP use SET instead of SELECT if u can....btw it doesn't matter much
精彩评论