C#--两层架构基于OOP实现对象添加到数据库
来源:互联网 发布:java发送微信消息接口 编辑:程序博客网 时间:2024/05/19 15:40
准备的工作
俩层架构的框架
1-数据访问层—DAL;
2-实体类—Models;
3-UI层—StudentManagePro;
总体架构展示:
SQL表:
UI界面展示
编写后台方法StudentService.cs
using System;using System.Collections.Generic;using System.Linq;using System.Text;using Models;namespace DAL{ //添加学员对象数据访问类 public class StudentService { //添加学员对象 public int AddStudent(Students objStudent) { string sql = "insert into Students (StudentName,Age,Gender,Bitrthday,"; sql += "CardNo,ClassId,StudentIdNo,PhoneNumber,StudentAddress,StuImage) "; sql += " Values('{0}',{1},'{2}','{3}','{4}',{5},{6},'{7}','{8}','{9}')"; sql = string.Format(sql, objStudent.StudentName, objStudent.Age, objStudent.Gender, objStudent.Birthday.ToString("yyyy-MM-dd"), objStudent.CardNo, objStudent.ClassId, objStudent.StudentIdNo, objStudent.PhoneNumber, objStudent.StudentAddress, objStudent.StuImage); try { return SQLHelper.Update(sql); } catch (Exception ex) { throw new Exception("保存数据出现问题" + ex.Message); } } }}
封装对象
//封装学员对象 Students objStudent = new Students() { StudentName = this.txtStuName.Text.Trim(), Gender = this.rdoMale.Checked ? "男" : "女", Birthday = Convert.ToDateTime(this.txtBirthday.Text), Age = DateTime.Now.Year - Convert.ToDateTime(this.txtBirthday.Text).Year, ClassId = Convert.ToInt32(this.cboClssName.SelectedValue), StudentIdNo = Convert.ToDecimal(this.txtStuIdNo.Text.Trim()), CardNo = this.txtCardNo.Text.Trim(), PhoneNumber = this.txtPhoneNumber.Text.Trim(), StudentAddress = this.txtStudAddress.Text.Trim(), StuImage = this.pbStu.Image == null?"":new Common.SerializeObjectToString() .SerializeObject(this.pbStu.Image) };
提交对象
创建后台访问对象:
SQL表格内容:
阅读全文
0 0
- C#--两层架构基于OOP实现对象添加到数据库
- 利用Delphi实现两层C/S数据库应用程序设计
- 基于对象的程序设计(OOP)
- .:::::利用Delphi实现两层C/S数据库应用程序设计简介 :::::.
- 在c#中实现3层架构
- [类和对象]-C#OOP
- C#OOP之类和对象
- EF架构~基于EF数据层的实现
- C语言实现的OOP
- MVC与B/S,C/S结构,三层架构/两层架构 的关系
- 三层架构之数据库访问层完全篇(C#)
- 三层架构之数据库访问层完全篇(C#)
- 三层架构之数据库访问层完全篇(C#)
- 三层架构之数据库访问层完全篇(C#)
- 三层架构之数据库访问层完全篇(C#)
- 三层架构之数据库访问层完全篇(C#)
- 基于PB的C/S两层结构向基于Web分布式应用的平滑过度
- 基于PB的C/S两层结构向基于Web分布式应用的平滑过度
- 学习笔记TF051:生成式对抗网络
- c#--将图片转换为二进制序列字符串
- java初次理解
- 初识Qt绘图QGraphicsItem
- 过TesSafe反WinDbg双机调试
- C#--两层架构基于OOP实现对象添加到数据库
- Spark-Streaming编程指南
- 【Leetcode】【python】Remove Nth Node From End of List
- 数据结构编程笔记十四:第六章 树和二叉树 二叉树基本操作及四种遍历算法的实现
- Qt学习之路(32): 一个简易画板的实现(Graphics View)
- 魏新是方正“窝案”的总指挥
- [Leetcode][链表]相关题目汇总/分析/总结
- Qt中QGraphics类坐标映射关系详解(有图有真相,实例讲解)
- QT