• 使用NbearLite的数据库操作方法


    首先要创建一个Database实例,参数是connectionStrings里的链接字符串的名字

    <connectionStrings>
            <add name="mainDB" connectionString="Database=OA_new_test;Server=.;
                                             Uid=sa;Pwd=App1234;Enlist=False;
                                             Pooling=true;Connection Reset=false;
                                             Trusted_Connection=no;Connect TimeOut=3000;"
                                providerName="System.Data.SqlClient"/>
    <connectionStrings>

    protected NBearLite.Database db = new NBearLite.Database("mainDB");

     

    新增

    public void Insert(wupin_apply_detail wp)
            {
                InsertSqlSection iss = db.Insert(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail);

                iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wa_id, wp.wa_id);
                iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_id, wp.wp_apply_id);
                iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_name, wp.wp_apply_name);
                if (wp.wp_apply_time != DateTime.MaxValue)
                    iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_time, wp.wp_apply_time);
                iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_uid, wp.wp_apply_uid);
                iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_name, wp.wp_name);
                iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_quantity, wp.wp_quantity);


                int i = iss.ExecuteReturnAutoIncrementID(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.id);
                wp.id = i;
            }
    修改:

    public int Update(wupin_apply_detail wp)
            {
                UpdateSqlSection iss = db.Update(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail);

                iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wa_id, wp.wa_id);
                iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_id, wp.wp_apply_id);
                iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_name, wp.wp_apply_name);
                if (wp.wp_apply_time != DateTime.MaxValue)
                    iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_time, wp.wp_apply_time);
                iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_apply_uid, wp.wp_apply_uid);
                iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_name, wp.wp_name);
                iss = iss.AddColumn(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.wp_quantity, wp.wp_quantity);
                iss = iss.Where(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.id == 1);

                int i = iss.Execute();
                return i;
            }
    查询实体:
            public wupin_apply_detail GetEntity(int id)
            {
                IDataReader dr = db.Select(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail).Where(Beyondbit.OA.DataAccess.Tables.wupin_apply_detail.id == id).ToDataReader();
                return ParseEntity(dr);
            }

            public wupin_apply_detail ParseEntity(IDataReader dr)
            {
                wupin_apply_detail entity = null;
                if (dr.Read())
                {
                    entity = new wupin_apply_detail();
                    
                      if (dr["id"] != null)
                        entity.id = Convert.ToInt32(dr["id"]);
                      if (dr["wp_name"] != null)
                        entity.wp_name = Convert.ToString(dr["wp_name"]);
                      if (dr["wp_quantity"] != null)
                        entity.wp_quantity = Convert.ToInt32(dr["wp_quantity"]);
                      if (dr["wp_apply_id"] != null)
                        entity.wp_apply_id = Convert.ToInt32(dr["wp_apply_id"]);
                      if (dr["wp_apply_uid"] != null)
                        entity.wp_apply_uid = Convert.ToString(dr["wp_apply_uid"]);
                      if (dr["wp_apply_name"] != null)
                        entity.wp_apply_name = Convert.ToString(dr["wp_apply_name"]);
                      if (dr["wp_apply_time"] != null)
                        entity.wp_apply_time = Convert.ToDateTime(dr["wp_apply_time"]);
                      if (dr["wa_id"] != null)
                        entity.wa_id = Convert.ToInt32(dr["wa_id"]);
                                    dr.Close();
                }            
                
                return entity;
            }
     

  • 相关阅读:
    Pytorch1.0入门实战二:LeNet、AleNet、VGG、GoogLeNet、ResNet模型详解
    Pytorch1.0入门实战一:LeNet神经网络实现 MNIST手写数字识别
    浅谈RNN、LSTM + Kreas实现及应用
    tensorflow 1.12.0 gpu + python3.6.8 + win10 + GTX1060 + cuda9.0 + cudnn7.4 + vs2017)
    高手详解SQL性能优化十条经验
    SQL语句操作符优化
    SQL优化
    34条简单的SQL优化准则
    销售订单无法使用折扣(其他可以正常使用)
    EBS FORM FOLDER 开发,单元格无法使用右键
  • 原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/2155704.html
Copyright © 2020-2023  润新知