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 }
很早以前写的,你看看吧!