在C#中调用Storeprocedure [英] Calling Storeprocedure in c#

查看:114
本文介绍了在C#中调用Storeprocedure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已经创建了一个存储过程spLogin.此过程检查是否存在用户名和密码(如果是),则返回1;如果不存在,则返回1;返回-1

但是我正在输入正确的用户名和密码,但是存储过程返回的值-1我的Qurey在下面

Hi,
i have create one store procedure spLogin.this procedure check wheather user name and password exist or not if yes return 1 if not exist return -1

but i am entering right user name and password but the store procedure returning value -1 my qurey is below

SqlCommand cmd = new SqlCommand("spLogin", open());
           cmd.CommandType = CommandType.StoredProcedure;

           cmd.Parameters.Add("@LoginName", SqlDbType.VarChar).Value = clsComm.LoginName;
           cmd.Parameters.Add("@Loginpassword ", SqlDbType.VarChar).Value = clsComm.Loginpassword;

           result=cmd.ExecuteNonQuery();


请帮帮我


Please help me out

推荐答案

如果您在 ^ ]存储过程实际返回的内容.我也想知道您使用的是ExecuteNonQuery,就像我期望的那样会返回数据. ExecuteNonQuery通常用于对数据进行更改,例如UPDATE,INSERT或DELETE.
It would be better if you check in profiler [^]what you stored procedure actually returns. I am also wondering that you use ExecuteNonQuery, where as I would expect data to be returned. ExecuteNonQuery is usually used to perform a change in data such as UPDATE, INSERT or DELETE.


创建一个存储过程,接受名称作为输入....从该名称返回密码当前名称...检查文本框中的值和该过程的结果是否相同...
Create a stored procedure that accepts the name as input ....From that name return the password of current name...Check if both the value in text box and the result from the procedure is same or not...
string Password="";
SqlDataReader ObjReader=null;
SqlCommand cmd = new SqlCommand("spLogin", open());
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@LoginName", TextBoxUserName.ToString());
ObjReader=cmd.ExecuteReader();
while(ObjReader.read())
{
   Password=ObjReader[0].toString();

}
if(Password==TextBoxPassword.toString())
{
    //User Exists;
}
else
{
    UserName are password wrong;
}


不要使用result=cmd.ExecuteNonQuery();
代替使用
result=cmd.excutescalar();
比我希望你的问题会解决.
don''t use result=cmd.ExecuteNonQuery();
in place of use
result=cmd.excutescalar();
than i hope your problem will sort out.


这篇关于在C#中调用Storeprocedure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆