我在做忘记密码,我写下面的代码.但是我得到了错误.那就是size属性的大小为0. [英] i am doing forgotpassword,i write the code below.but i got error .that is the size property has invalid size of 0.
本文介绍了我在做忘记密码,我写下面的代码.但是我得到了错误.那就是size属性的大小为0.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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;
}
推荐答案
可能应该在存储过程中指定Size参数.
您可以提供tutor_Retrievepassword过程的SQL吗?
Possibly you should specify Size argument in yours stored procedure.
Can you provide SQL of tutor_Retrievepassword procedure?
调试代码以查看哪一行会引发错误.
如果执行查询(cmd.ExecuteReader()
)
尝试在SQL Server查询分析器上使用相同的参数运行存储过程,并检查存储过程是否成功.
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.
在上面的代码中,您正在使用nvarchar.默认情况下,此数据类型包含1个字符(第一个字符).在这里,如果您在Sql参数中提到了大小,那么您提到的错误将不会出现.您可以尝试查看结果. :)
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. :)
这篇关于我在做忘记密码,我写下面的代码.但是我得到了错误.那就是size属性的大小为0.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文