virlinz
May 15th, 2005, 11:30 AM
Hi..
I have a problem with implementing a stored procedure which returns a value to the caller..
I want to verify whether the given username and email address exist in the database. The return value of the stored procedure will determine whether the input matches.
This is my stored procedure
CREATE PROCEDURE dbo.RetrievePassword
(
@Username varchar(25),
@EMail varchar(40)
)
AS
DECLARE @intValid int
SELECT @intValid = COUNT(*)
FROM Profile where Username = @Username AND EMail = @EMail
Return @intValid
This is my C# codes under the button click function
SqlConn = new SqlConnection(ConfigurationSettings.AppSettings["SqlServerSite"]);
cmdRetrieve = new SqlCommand("RetrievePassword", SqlConn);
cmdRetrieve.CommandType = CommandType.StoredProcedure;
cmdRetrieve.Parameters.Add("@Username", SqlDbType.VarChar, 25).Value = txtUsername;
cmdRetrieve.Parameters.Add("@EMail", SqlDbType.VarChar, 40).Value = txtEmailAdd;
SqlParameter PrmReturn = new SqlParameter("@intReturn", SqlDbType.Int);
PrmReturn.Direction = ParameterDirection.ReturnValue;
SqlConn.Open();
cmdRetrieve.ExecuteNonQuery();
SqlConn.Close();
int intValid = Convert.ToInt32(PrmReturn.Value);
if(intValid != 0)
Response.Write("EMail has been sent");
else
Response.Write("Details not matched");
The error is Object must implement IConvertible[/COLOR]. The source error is at the cmdRetrieve.ExecuteNonQuery() line.
Where did I do wrong? I followed an example in VB.NET (and made some changes)on passing value from stored procedure I found on the Internet. Please shed some light for me. Thanks in advance.
I have a problem with implementing a stored procedure which returns a value to the caller..
I want to verify whether the given username and email address exist in the database. The return value of the stored procedure will determine whether the input matches.
This is my stored procedure
CREATE PROCEDURE dbo.RetrievePassword
(
@Username varchar(25),
@EMail varchar(40)
)
AS
DECLARE @intValid int
SELECT @intValid = COUNT(*)
FROM Profile where Username = @Username AND EMail = @EMail
Return @intValid
This is my C# codes under the button click function
SqlConn = new SqlConnection(ConfigurationSettings.AppSettings["SqlServerSite"]);
cmdRetrieve = new SqlCommand("RetrievePassword", SqlConn);
cmdRetrieve.CommandType = CommandType.StoredProcedure;
cmdRetrieve.Parameters.Add("@Username", SqlDbType.VarChar, 25).Value = txtUsername;
cmdRetrieve.Parameters.Add("@EMail", SqlDbType.VarChar, 40).Value = txtEmailAdd;
SqlParameter PrmReturn = new SqlParameter("@intReturn", SqlDbType.Int);
PrmReturn.Direction = ParameterDirection.ReturnValue;
SqlConn.Open();
cmdRetrieve.ExecuteNonQuery();
SqlConn.Close();
int intValid = Convert.ToInt32(PrmReturn.Value);
if(intValid != 0)
Response.Write("EMail has been sent");
else
Response.Write("Details not matched");
The error is Object must implement IConvertible[/COLOR]. The source error is at the cmdRetrieve.ExecuteNonQuery() line.
Where did I do wrong? I followed an example in VB.NET (and made some changes)on passing value from stored procedure I found on the Internet. Please shed some light for me. Thanks in advance.