zoukankan      html  css  js  c++  java
  • OOP典型应用:实体类

    (1)实体类是业务对象的基础,它用面向对象的思想消除了关系数据与对象之间的差异

       实体类:

     public class Department
        {
            public int BId { get; set; }
            public int BName{ get; set; }
        
        }
    

      

    public class Employee
        {
            public int YId{ get; set; }
            public int YName{ get; set; }
            public int BId{ get; set; }
            public int ZId{ get; set; }
        }
    

      

     public class Task
        {
            public string Contents {get;set;}
            public int RId {get;set;}
            public int YId {get;set;}
            public DateTime Time {get;set;}
            public int Hours {get;set;}
            public string Type { get; set; }
        }
    

      数据访问层:

    public  class InfoAddDAL
        {
    
            public bool Add(string name)
            {
                bool falg = false;
                string sql = "insert into ProgramInfo(pname) values('"+name+"')";
                int num=SQLHelper.ExecuteNonQuery(sql);
                if(num==1)
                {
                    falg= true;
                }
                return falg;
            }
    
            public DataTable SelectInfo()
            {
                List<string> list = new List<string>();
              
                try
                {   
                    string sql = "select pname from ProgramInfo";
                    DataTable table=SQLHelper.ExecuteDataTable(sql);         
                    return table;
                
                }
                catch (SqlException ex)
                {
    
                    throw ex;
                }
                catch(Exception ex)
                {
                    throw ex;
                }  
            }
    
            public bool DeleteInfo(string name)
            {
                bool falg = false;
                try
                {
                    string sql = "delete ProgramInfo where pname='" + name + "'";
                    int num=SQLHelper.ExecuteNonQuery(sql);
                    if (num == 1)
                    {
                        falg= true;
                    }
                    return falg;
                }
                catch (SqlException ex)
                {
    
                    throw ex;
                }
                catch(Exception ex)
                {
                    throw ex;
    
                }
              
            }
    
            public bool UpdateInfo(string name,string names)
            {
                bool falg = false;       
                string sql = "Update  ProgramInfo set pname='"+name+"'where pname='"+names+"'";
                int num=SQLHelper.ExecuteNonQuery(sql);
                if(num==1)
                {
                    falg= true;
                }
                return falg;
            }
        }
    

      在这里再引用一个App.config

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <connectionStrings>
        <add name="constr" connectionString="data source=.; initial catalog=AddInfo; uid=sa;">  
        </add>
      </connectionStrings>
        <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
        </startup>
    </configuration>
    

      

    (2)const和readonly的区别

       (1)readonly只能修饰类变量   const修饰成员变量和局部变量

       (2)readonly在运行时赋值,const在编译时赋值

       (3)const只能修饰值类型和特殊的引用类型  readonly可以修饰任何类型

  • 相关阅读:
    [Oracle11g]安装提示不能使用/usr/bin/xdpyinfo命令
    [shell]时间判断
    Share 简易网盘
    VSCODE代码上下对齐插件 — Better Align
    关于 vscode intelephense 错误提示的问题
    2021/11/08 集训补题
    [国家集训队]墨墨的等式
    马大师的分块练习
    20211109 集训补题
    弱智的 线性代数 学习笔记
  • 原文地址:https://www.cnblogs.com/sunbin123/p/6661349.html
Copyright © 2011-2022 走看看