帮我写一个一个用c#.net连接sqlserver数据库做成的登录系统
2个回答
2013-09-04
展开全部
不是我们书上如何如何,这个登陆无非就是一个简单的检索模块。
我贴一小段代码给你看,你就知道登陆无非就是几行代码的事情。
开发工具VS2008,数据库SQL SERVER 2005,
持久层,基于ADO.NET的LINQ to sql
/// <summary>
/// 登陆检测
/// </summary>
/// <param name="id"></param>
/// <param name="pwd"></param>
/// <returns></returns>
public bool SearchUser(string id, string pwd)
{
try
{
var resualt = ct.account.Single(u => u.name == id && u.pwd == pwd);
return true;//返回true,就登陆成功,要是返回false,就登陆失败.
}
catch
{
return false;
}
}
我贴一小段代码给你看,你就知道登陆无非就是几行代码的事情。
开发工具VS2008,数据库SQL SERVER 2005,
持久层,基于ADO.NET的LINQ to sql
/// <summary>
/// 登陆检测
/// </summary>
/// <param name="id"></param>
/// <param name="pwd"></param>
/// <returns></returns>
public bool SearchUser(string id, string pwd)
{
try
{
var resualt = ct.account.Single(u => u.name == id && u.pwd == pwd);
return true;//返回true,就登陆成功,要是返回false,就登陆失败.
}
catch
{
return false;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-04
展开全部
public class AdminService
{
private readonly string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
private readonly string dboOwner = ConfigurationManager.ConnectionStrings["dboOwner"].ToString();
public AdminService() { }
public Admin GetAdmin(string name, string password)
{
Admin admin = new Admin();
try
{
using (SqlConnection connection = new SqlConnection(connStr))
{
SqlCommand command = new SqlCommand(dboOwner + ".usp_SelectAdmin", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@AdminName", SqlDbType.VarChar, 30).Value = name;
command.Parameters.Add("@AdminPwd", SqlDbType.VarChar, 30).Value = password;
connection.Open();
using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
{
if (reader.Read())
{
admin.Name = Convert.ToString(reader["AdminName"]).Trim();
admin.Password = Convert.ToString(reader["AdminPwd"]).Trim();
}
reader.Close();
reader.Dispose();
}
connection.Close();
connection.Dispose();
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return admin;
}
}
三层体系的
{
private readonly string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
private readonly string dboOwner = ConfigurationManager.ConnectionStrings["dboOwner"].ToString();
public AdminService() { }
public Admin GetAdmin(string name, string password)
{
Admin admin = new Admin();
try
{
using (SqlConnection connection = new SqlConnection(connStr))
{
SqlCommand command = new SqlCommand(dboOwner + ".usp_SelectAdmin", connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@AdminName", SqlDbType.VarChar, 30).Value = name;
command.Parameters.Add("@AdminPwd", SqlDbType.VarChar, 30).Value = password;
connection.Open();
using (SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection))
{
if (reader.Read())
{
admin.Name = Convert.ToString(reader["AdminName"]).Trim();
admin.Password = Convert.ToString(reader["AdminPwd"]).Trim();
}
reader.Close();
reader.Dispose();
}
connection.Close();
connection.Dispose();
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return admin;
}
}
三层体系的
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询