zoukankan      html  css  js  c++  java
  • SqlParameter 用法总结

    作用

    解决恶意的T-sql语句攻击第一种

     //传入参数  string ProductGroupCode, string Ismaintain, int HierarchyID, string BOMName,string BOMCode, string BOMType, int BOPStepType, int PageIndex, int PageSize, out int TotalCount

    public static DataTable GetBOPStepByBOM(string ProductGroupCode, string Ismaintain, int HierarchyID, string BOMName,string BOMCode, string BOMType, int BOPStepType, int PageIndex, int PageSize, out int TotalCount) { SqlParameter[] parameters = { new SqlParameter("@ProductGroupCode", SqlDbType.VarChar), //自定义参数 与参数类型 new SqlParameter("@Ismaintain", SqlDbType.VarChar), new SqlParameter("@HierarchyID", SqlDbType.Int), new SqlParameter("@BOMName", SqlDbType.VarChar), new SqlParameter("@BOMType", SqlDbType.VarChar), new SqlParameter("@BOPStepType", SqlDbType.Int), new SqlParameter("@PageIndex", SqlDbType.Int), new SqlParameter("@PageSize", SqlDbType.Int), new SqlParameter("@TotalCount", SqlDbType.Int), new SqlParameter("@BOMCode", SqlDbType.VarChar), }; parameters[0].Value = ProductGroupCode; //给参数赋值 parameters[1].Value = Ismaintain; parameters[2].Value = HierarchyID; parameters[3].Value = BOMName; parameters[4].Value = BOMType; parameters[5].Value = BOPStepType; parameters[6].Value = PageIndex; parameters[7].Value = PageSize; parameters[8].Direction = ParameterDirection.Output; parameters[9].Value = BOMCode; SqlDataAccess sqlDataAccess = SqlDataAccess.CreateDataAccess(); //自定义帮助类 主要作用 开始 执行 关闭 ADO.net DataSet result = sqlDataAccess.ExecuteDataSet("up_BasicInfo_GetBOPStepListByBOM", parameters); //这里执行的是存储过程 并接收返回值 TotalCount = parameters[8].Value == DBNull.Value ? default(int) : (int)parameters[8].Value; return result.Tables[0]; //最终返回执行结果 }


    第二种

       public static int InsertOrderCause(string productGroupCode, int customerBelongTo, int salesTypeID,
                string orderCauseList)
            {
                int ret = 0;
    
                SqlParameter[] paras =
                {
                    new SqlParameter("@ProductGroupCode",productGroupCode),  //不声明变量类型 直接进行复制
                    new SqlParameter("@CustomerBelongTo",customerBelongTo),
                    new SqlParameter("@SalesTypeID",salesTypeID),
                    new SqlParameter("@OrderCauseList",orderCauseList)
                };
    
                SqlDataAccess sqlDataAccess = SqlDataAccess.CreateDataAccess();
                ret = sqlDataAccess.ExecuteNonQuery("up_BasicInfo_InsertOrderCause", paras);
    
                return ret;
            }

     

  • 相关阅读:
    Debian/Ubuntu/Raspbian 时间同步
    linux 安裝mitmproxy
    Raspbian Lite Guide GUI 树莓派安装桌面
    SSH连接 提示 ssh_exchange_identification: Connection closed by remote host
    Navicat15 永久激活版教程
    docker企业级镜像仓库Harbor管理
    centos7.4安装docker
    Linux系统硬件时间12小时制和24小时制表示设置
    windows server 2012 R2系统安装部署SQLserver2016企业版(转)
    细说show slave status参数详解
  • 原文地址:https://www.cnblogs.com/szlblog/p/6370489.html
Copyright © 2011-2022 走看看