All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
一个使用存储过程实现的用户登录功能(含代码)_[Asp.Net教程]

Writer: 归海一刀 Article type: Programming skills(编程技巧) Time: 2014/1/30 1:30:27 Browse times: 232 Comment times: 0

一个使用存储过程实现的用户登录功能(含代码)_[Asp.Net教程]


Head photo

Go homepage
Upload pictures
Write articles

一个使用存储过程实现的用户登录功能(含代码)_[Asp.Net教程] 程序代码:

public SqlDataReader GetUserLoginByProc(string sUserName,string sPassword)
{
///创建链接
SqlConnection myConnection = new SqlConnection(
ConfigurationManager.ConnectionStrings["数据库连接字符"].ConnectionString);

///创建Command
SqlCommand myCommand = new SqlCommand("Pr_GetUserLogin",myConnection);
///设置为执行存储过程
myCommand.CommandType = CommandType.StoredProcedure;

///添加存储过程的参数
SqlParameter pUserName = new SqlParameter("@UserName",SqlDbType.VarChar,32);
pUserName.Value = sUserName;
myCommand.Parameters.Add(pUserName);

SqlParameter pPassword = new SqlParameter("@Password",SqlDbType.VarChar,255);
pPassword.Value = sPassword;
myCommand.Parameters.Add(pPassword);

///定义DataReader
SqlDataReader dr = null;
try
{
///打开链接
myConnection.Open();
///读取数据
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
}
catch(SqlException ex)
{
///抛出异常
throw new Exception(ex.Message,ex);
}
///返回DataReader
return dr;
}


存储过程代码:

CREATE PROCEDURE Pr_GetUserLogin
(
@UserName varchar(32),
@Password varchar(255)
)

AS

SELECT
UserID
FROM
Users
WHERE
UserName = @UserName AND Password = @Password

GO





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.