Click here to Skip to main content
15,890,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public string forgotpassword(string tutor_username, string tutor_email)
{
    SqlConnection con = new SqlConnection(StrCon);
    SqlCommand cmd = new SqlCommand();
    con.ConnectionString = StrCon;
    //DataSet resultds = new DataSet();
    cmd.Connection = con;
    cmd.CommandType = CommandType.StoredProcedure;
    //SqlDataAdapter da = new SqlDataAdapter();
    cmd.CommandText = "tutor_Retrievepassword";
    cmd.Parameters.Add("@tutor_username", SqlDbType.NVarChar).Direction = ParameterDirection.Input;
    cmd.Parameters.Add("@tutor_password", SqlDbType.NVarChar).Direction = ParameterDirection.Output;
    cmd.Parameters.Add("@tutor_email", SqlDbType.NVarChar).Direction = ParameterDirection.Input;
    cmd.Parameters["@tutor_username"].Value = tutor_username;
    //cmd.Parameters["@password"].Value = password;
    cmd.Parameters["@tutor_email"].Value = tutor_email;
    // da.SelectCommand = cmd;
    
    try
    {
        con.Open();
        cmd.ExecuteReader();
        return cmd.Parameters["@tutor_password"].ToString();
        // da.Fill(resultds);
    }
    catch (Exception ex)
    {
        throw ex;
        //  return null;
    }
    finally
    {
        cmd.Dispose();
        con.Close();
        con.Dispose();
    }
    //return resultds;
}
Posted
Updated 7-Apr-10 23:09pm
v3

Possibly you should specify Size argument in yours stored procedure.

Can you provide SQL of tutor_Retrievepassword procedure?
 
Share this answer
 
Debug the code to see which line throws the error.
If it's on execution of query (cmd.ExecuteReader())
try running the stored procedure with same parameters on SQL Server Query Analyzer and check if it succeeds there.
 
Share this answer
 
In the above code you are using nvarchar. This data type by default hold 1 characters(the first one). Here if you mention the size in Sql Parameter, then the error you mentioned will not come. You may try and see the result. :)
 
Share this answer
 
try adding:

cmd.Parameters["@tutor_email"].Size = tutor_email.Length;
cmd.Parameters["@tutor_username"].Size= tutor_username.Length;


??
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900