<connectionStrings><add name="StudentM" connectionString="Database=StudentM;Server=.;Integrated Security=false;Uid=sa;PassWord=123;" providerName="System.Data.SqlClient"/></connectionStrings>
public enum DataBaseEnum{//改這個地方為Web.config的數據庫節點名,如果多個數據庫就在后面加XXX=2StudentM = 1}
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;//引入類庫using com.Model.Base; namespace Model.StudentM{//繼承BseModel(命名空間為com.Model.Base的Model.Base的類庫)public class AdminInfo: BaseModel{public AdminInfo(){//設主鍵PrimaryKey = "AdminId";//數據庫名為DataBaseEnum下的StudentMDataBaseName = DataBaseEnum.StudentM;}//寫所有的列名字段,記得類型要一致public int AdminId{//get和set分別表示可讀和可寫get;set;}public string UserName{get;set;}public string Pwd{get;set;}}}
//記得引入using Model.StudentM;using com.DAL.Base; namespace Dal.StudentM{public class AdminInfoDal{//BaseDAL是一個對象,所有的增刪改查的方法什么的都放在BaseDAL//用靜態是因為通過類去調用m_AdminInfo就更簡單,不用實例化public static BaseDAL<AdminInfo> m_AdminInfo = new BaseDAL<AdminInfo>();}}
新聞熱點
疑難解答