//插入操作 public int InsertId_Card(Id_CardEntity t_Id_Card) { //定义插入数据的参数数组 SqlParameter[] p=new SqlParameter[]{ new SqlParameter("@User_id",t_Id_Card.User_id), new SqlParameter("@User_name",t_Id_Card.User_name), new SqlParameter("@User_id_card",t_Id_Card.User_id_card), new SqlParameter("@User_phone_num",t_Id_Card.User_phone_num), new SqlParameter("@User_pic_path",t_Id_Card.User_pic_path), new SqlParameter("@Teacher_id",t_Id_Card.Teacher_id) }; int i=SqlDBHelp.GetExecute("insert into Id_Card values (@User_id,@User_name,@User_id_card,@User_phone_num,@User_pic_path,@Teacher_id)", p) ; return i; }
//根据外键进行查询 public IList<Id_CardEntity> GetAllId_CardByuser_id(int t_user_id) { IList<Id_CardEntity> t_Id_Cards = new List<Id_CardEntity>(); SqlDataReader sdr = null; using(sdr=SqlDBHelp.GetReader("select * from Id_Card where user_id="+t_user_id)) { while(sdr.Read()) { Id_CardEntity t_Id_Card= new Id_CardEntity(); t_Id_Card.User_id=(int)sdr.GetValue(0); t_Id_Card.User_name=(string)sdr.GetValue(1); t_Id_Card.User_id_card=(string)sdr.GetValue(2); t_Id_Card.User_phone_num=(int)sdr.GetValue(3); t_Id_Card.User_pic_path=(string)sdr.GetValue(4); t_Id_Card.Teacher_id=(int)sdr.GetValue(5); t_Id_Cards.Add(t_Id_Card); } sdr.Close(); } return t_Id_Cards; }
public Id_CardEntity SelectId_CardByID(string t_user_id_card) { Id_CardEntity t_Id_Card= new Id_CardEntity(); SqlDataReader sdr=null; using(sdr=SqlDBHelp.GetReader("select * from Id_Card where user_id_card="+t_user_id_card)) { if(sdr.Read()) { t_Id_Card.User_id=(int)sdr.GetValue(0); t_Id_Card.User_name=(string)sdr.GetValue(1); t_Id_Card.User_id_card=(string)sdr.GetValue(2); t_Id_Card.User_phone_num=(int)sdr.GetValue(3); t_Id_Card.User_pic_path=(string)sdr.GetValue(4); t_Id_Card.Teacher_id=(int)sdr.GetValue(5); } } sdr.Close(); return t_Id_Card; }
public int UpdateId_Card(Id_CardEntity t_Id_Card) { SqlParameter[] p=new SqlParameter[]{ new SqlParameter("@User_id",t_Id_Card.User_id), new SqlParameter("@User_name",t_Id_Card.User_name), new SqlParameter("@User_id_card",t_Id_Card.User_id_card), new SqlParameter("@User_phone_num",t_Id_Card.User_phone_num), new SqlParameter("@User_pic_path",t_Id_Card.User_pic_path), new SqlParameter("@Teacher_id",t_Id_Card.Teacher_id) }; int i=SqlDBHelp.GetExecute("update Id_Card set user_name=@User_name,user_id_card=@User_id_card,user_phone_num=@User_phone_num,user_pic_path=@User_pic_path,teacher_id=@Teacher_id where user_id_card=@User_id_card", p) ; return i; }
//插入操作 public static int InsertId_Card(Id_CardEntity t_Id_Card) { int i=-1; //定义插入数据的参数数组 try { i=dal.InsertId_Card(t_Id_Card); } catch(Exception ex) { throw new Exception(ex.Message); } return i; }