C#,Ado.net常用方法

//dataSet转dataTble
 private DataTable convertToDataTable(DataSet ds)
        {
            DataTable dt = new DataTable();
            dt = ds.Tables[0];
            return dt;
        }
//DAL层执行存储过程
 public DataSet CreateAIQR_Protocol_Carry(string wxid, string stime, out string excelname)
        {
            SqlParameter[] param =
            {
                new SqlParameter("@WxID",SqlDbType.NVarChar,50),
                new SqlParameter("@sTime",SqlDbType.NVarChar,50),
                new SqlParameter("@excelNameOut",SqlDbType.NVarChar,255)
            };

            param[0].Value = wxid;
            param[1].Value = stime;
            param[2].Direction = ParameterDirection.Output;
            var ds = DbHelperSQL.RunProcedure("CreateAIQR_Protocol_progress_CITY", param, "ds");
            excelname = param[2].Value.ToString();
            return ds;
        }

        /// 
        ///获取配置文件里面存储的数据
        /// 
        /// key
        /// value
        public static string GetConfigValue(string _configKey)
        {
            string _value = ConfigurationManager.AppSettings[_configKey] ?? "";
            return _value;
        }
        /// 
        /// JSON转对象
        /// 
        /// 对象
        /// json字符串
        /// 
        public static T JsonToObject(string jsonString)
        {
            return JsonConvert.DeserializeObject(jsonString);
        }
        //MD5 参数为字符串和编码格式
         public static string Get_MD5(string strSource, string sEncode)
        {
            //new 
            System.Security.Cryptography.MD5 md5 = new MD5CryptoServiceProvider();

            //获取密文字节数组
            byte[] bytResult = md5.ComputeHash(Encoding.GetEncoding(sEncode).GetBytes(strSource));

            //转换成字符串,并取9到25位 
            //string strResult = BitConverter.ToString(bytResult, 4, 8);  
            //转换成字符串,32位 

            string strResult = BitConverter.ToString(bytResult);

            //BitConverter转换出来的字符串会在每个字符中间产生一个分隔符,需要去除掉 
            strResult = strResult.Replace("-", "");

            return strResult;
        }

         /// 
        /// 日志记录
        /// 
        /// 日志路径
        /// 日志名称
        /// 日志内容
        private void log(string filepath,string filename,string content)
        {
            if (!File.Exists(filepath+filename+".txt"))
            {
                FileStream fs1 = new FileStream(filepath + filename+".txt", FileMode.Create, FileAccess.Write);//创建写入文件 
                StreamWriter sw = new StreamWriter(fs1,Encoding.GetEncoding("gb2312"));
                sw.WriteLine(content);//开始写入值
                sw.Close();
                fs1.Close();
            }
            else
            {
                FileStream fs = new FileStream(filepath + filename+".txt", FileMode.Append, FileAccess.Write);
                StreamWriter sr = new StreamWriter(fs,Encoding.GetEncoding("gb2312"));
                sr.WriteLine(content);//开始写入值
                sr.Close();
                fs.Close();
            }
        }

你可能感兴趣的:(C#,Ado.net常用方法)