用于登录的存储过程 [英] stored procedure for login

查看:84
本文介绍了用于登录的存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有表'登录(用户名,密码,名称)'。

我想创建登录的stroed程序。我有c#代码,但我想从我想要的存储过程存储过程返回指定。



c#代码如下......

I have table 'login(username,password,designation)'.
I want to create stroed procedure to login.I have c# code for that but I want stored procedure from stored procedure I want to return designation.

c# code is following...

string s = "select UserName,Password,Designation from Login where UserName=@uname and  Password=@pass";
               SqlCommand cmd1 = new SqlCommand(s, con);
               cmd1.Parameters.AddWithValue("@uname", TextBox1.Text);
               cmd1.Parameters.AddWithValue("@pass", TextBox2.Text);
               SqlDataReader dr = cmd1.ExecuteReader(CommandBehavior.SingleRow);

推荐答案



试试这个

Hi ,
Try this
CREATE PROCEDURE usp_Login
(
@uname NVARCHAR(50),  @pass NVARCHAR(50)
)
AS
BEGIN
SET NOCOUNT ON;
SELECT  UserName,[Password],Designation
FROM dbo.Login
WHEREUserName=@uname AND [Password]=@pass
end





最好的问候

M.Mitwalli



Best Regards
M.Mitwalli


如果您不熟悉存储过程,你可以看到这篇CP文章

Sql服务器 - 如何在Sql server中编写存储过程 [ ^ ]



存储过程的基础知识





SP用于登录,请参阅此示例

http://www.dotnetspider.com/resources/20412 -login-stored-procedures.aspx [ ^ ]
If you are new to stored procedure,you can see this CP Article
Sql Server - How to write a Stored procedure in Sql server[^]
and
Basics of Stored Procedure


SP for login,see this Example
http://www.dotnetspider.com/resources/20412-login-stored-procedures.aspx[^]






示例一个 [ ^ ]



示例二 [ ^ ]



在存储过程中使用以下查询

Hi,

Sample one[^]

Sample two[^]

Use the following Query in stored procedure
select @INtegerVariable = count(UserName) from Login where UserName=@uname and  Password=@pass





然后



then

Select @INtegerVariable

....



如果@INtegerVariable的值为1,则登录成功,否则为否。



问候

Sebastian

....

If the value of @INtegerVariable is 1 then login is successful, else no.

Regards
Sebastian


这篇关于用于登录的存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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