首页 新闻 搜索 专区 学院

求一段 c# winform使用access数据库的登入代码

0
悬赏园豆:10 [待解决问题]

程序需要实现登入功能,使用access数据库    登入时  查询当前准备登入的用户是否已登入  若已登入则返回提示   程序只实现密码登入    也就是说  只要输入数据库里密码字段有的值   就可以登入  

 

求实现这个功能的代码  谢谢

小红豆的主页 小红豆 | 初学一级 | 园豆:194
提问于:2012-08-09 21:49
< >
分享
所有回答(1)
0

access 和 ms sql 只是在连接时 不一样呢,

 

1 <connectionStrings>
2     <add name="OledbConn" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|test.mdb"/>
3   </connectionStrings>

 

基本查询类似的啊,

 

 1 public Model.Manager ValidationLogin(string accounts,string password)
 2         {
 3            OleDbParameter[] parameters  = new OleDbParameter[2]
 4                 {
 5                     new OleDbParameter("@Accounts", OleDbType.VarChar, 50),
 6                     new OleDbParameter("@Password", OleDbType.VarChar, 50),
 7                     
 8                 };
 9 
10 
11             parameters[0].Value = accounts;
12             parameters[1].Value = password;
13 
14             try
15             {
16                 string strSql = "SELECT ID, Accounts,Password,IsValid,IsDelete,CreateDate,UpdateDate FROM tb_Manager WHERE IsValid =1 AND IsDelete = 0 AND Accounts=@Accounts AND Password=@Password ";
17 
18                 Model.Manager model = null;
19                 using (OleDbDataReader dReader = OleDbHelper.ExecuteReader(OleDbHelper.ConnectionString, CommandType.Text, strSql, parameters))
20                 {
21                     if (dReader.Read())
22                     {
23                         model = new Model.Manager();
24 
25                         model.ID = dReader["ID"] == DBNull.Value ? -1 : Convert.ToInt32(dReader["ID"]);
26                         model.Accounts = dReader["Accounts"] == DBNull.Value ? "" : dReader["Accounts"].ToString();
27                         model.Password = dReader["Password"] == DBNull.Value ? "" : dReader["Password"].ToString();
28                         model.IsValid = dReader["IsValid"] == DBNull.Value ? false : Convert.ToBoolean(dReader["IsValid"]);
29                         model.IsDelete = dReader["IsDelete"] == DBNull.Value ? true : Convert.ToBoolean(dReader["IsDelete"]);
30                         model.CreateDate = dReader["CreateDate"] == DBNull.Value ? DateTime.Now : Convert.ToDateTime(dReader["CreateDate"]);
31                         model.UpdateDate = dReader["UpdateDate"] == DBNull.Value ? DateTime.Now : Convert.ToDateTime(dReader["UpdateDate"]);
32 
33                         return model;
34                     }
35                 }
36                 return model;
37             }
38             catch (Exception e)
39             {
40                 throw e;
41             }
42         }


很早以前写的,你看看吧!

张坤 | 园豆:1865 (小虾三级) | 2012-08-09 23:11
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册