• 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可以修饰任何类型

  • 相关阅读:
    小白详细解析C#反射特性实例
    几种快速排序算法实现
    Redis中算法之——Raft算法
    redis中算法之——MurmurHash2算法
    关于typedef的用法
    gdb调试工具常用命令
    gcc 常用命令
    Linux 远程登录ssh服务器
    Linux 构建ftp服务器
    知乎话题结构以及相关内容抓取二(Redis存储)
  • 原文地址:https://www.cnblogs.com/sunbin123/p/6661349.html
Copyright © 2020-2023  润新知