在现在项目中,数据库操作类是必不可少.网络上也有很多开源的,我想大家比较熟悉的应该是sqlhelper,自己现在用的这份类也是参照网上的资料和以前同事代码中改了些,代码如下:
我的数据库操作类EMESqlHelperusing System;
我的数据库操作类EMESqlHelper
using System.Collections;
我的数据库操作类EMESqlHelper
using System.Data;
我的数据库操作类EMESqlHelper
using System.Data.SqlClient;
我的数据库操作类EMESqlHelper
using System.Xml;
我的数据库操作类EMESqlHelper
using System.Web;
我的数据库操作类EMESqlHelper
using EMEFRAME.CallDataBase;
我的数据库操作类EMESqlHelper
我的数据库操作类EMESqlHelper
namespace EMEFRAME.CallDataBase

调用例子:
1> 得到记录数
        /// <summary>
        /// 得到记录数
        /// </summary>
        /// <returns>返回int</returns>
        public static int getWB_SYS_UserCount(string sWhere)
        {
            int iCount = 0;
            try
            {
                using EMESqlHelper es = new EMESqlHelper())
                {
                    iCount = es.GetRecordCount("WB_SYS_User", sWhere);
                }
                return iCount;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
2> 带返回参数的存储过程调用(注意其中的InputOutput类型)
        /// <summary>
        /// 新增数据
        /// </summary>
        /// <param name="_obj">WB_SYS_UserEnt实体</param>
        /// <returns>返回bool值</returns>
        public static bool WB_SYS_UserAdd(WB_SYS_UserEnt _obj)
        {
            //*******************定义并赋值参数数组*******************//
            SqlParameter[] arParms = new SqlParameter[9];
            arParms[0] = new SqlParameter("AdminGroupID", SqlDbType.Int, 4);
            arParms[0].Direction = ParameterDirection.Input;
            arParms[0].Value = _obj.AdminGroupID;
            arParms[1] = new SqlParameter("Username", SqlDbType.NChar, 40);
            arParms[1].Direction = ParameterDirection.Input;
            arParms[1].Value = _obj.Username;
            arParms[2] = new SqlParameter("Password", SqlDbType.NChar, 64);
            arParms[2].Direction = ParameterDirection.Input;
            arParms[2].Value = _obj.Password;
            arParms[3] = new SqlParameter("RealName", SqlDbType.VarChar, 20);
            arParms[3].Direction = ParameterDirection.Input;
            arParms[3].Value = _obj.RealName;
            arParms[4] = new SqlParameter("MobileNum", SqlDbType.VarChar, 20);
            arParms[4].Direction = ParameterDirection.Input;
            arParms[4].Value = _obj.MobileNum;
            arParms[5] = new SqlParameter("PasswordAsk", SqlDbType.VarChar, 200);
            arParms[5].Direction = ParameterDirection.Input;
            arParms[5].Value = _obj.PasswordAsk;
            arParms[6] = new SqlParameter("PasswordAnswer", SqlDbType.VarChar, 200);
            arParms[6].Direction = ParameterDirection.Input;
            arParms[6].Value = _obj.PasswordAnswer;
            arParms[7] = new SqlParameter("Creater", SqlDbType.VarChar, 20);
            arParms[7].Direction = ParameterDirection.Input;
            arParms[7].Value = _obj.Creater;
            bool Exist = false;
            arParms[8] = new SqlParameter("Exist", SqlDbType.Bit, 1);
            arParms[8].Direction = ParameterDirection.InputOutput;
            arParms[8].Value = Exist;
            try
            {
                using EMESqlHelper es = new EMESqlHelper())
                {
                    es.ExecCommand("WB_SYS_User_Add", "1", arParms);
                    Exist = (bool)arParms[8].Value;
                }
                return !Exist;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
其中关联类SqlDataBase和DataBase的代码如下:
我的数据库操作类EMESqlHelperusing System;
我的数据库操作类EMESqlHelper
using System.Data;
我的数据库操作类EMESqlHelper
using System.Data.SqlClient;
我的数据库操作类EMESqlHelper
我的数据库操作类EMESqlHelper
namespace EMEFRAME.CallDataBase

我的数据库操作类EMESqlHelperusing System;
我的数据库操作类EMESqlHelper
using System.Data;
我的数据库操作类EMESqlHelper
我的数据库操作类EMESqlHelper
namespace EMEFRAME.CallDataBase

相关文章:

  • 2021-08-03
  • 2021-12-02
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-08
  • 2021-12-31
  • 2021-06-22
  • 2022-01-11
相关资源
相似解决方案