美文网首页
C#,Ado.net常用方法

C#,Ado.net常用方法

作者: ray_stronger | 来源:发表于2017-04-10 01:09 被阅读0次
    //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;
            }
    
            /// <summary>
            ///获取配置文件里面存储的数据
            /// </summary>
            /// <param name="_configKey">key</param>
            /// <returns>value</returns>
            public static string GetConfigValue(string _configKey)
            {
                string _value = ConfigurationManager.AppSettings[_configKey] ?? "";
                return _value;
            }
            /// <summary>
            /// JSON转对象
            /// </summary>
            /// <typeparam name="T">对象</typeparam>
            /// <param name="jsonString">json字符串</param>
            /// <returns></returns>
            public static T JsonToObject<T>(string jsonString)
            {
                return JsonConvert.DeserializeObject<T>(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;
            }
    
             /// <summary>
            /// 日志记录
            /// </summary>
            /// <param name="filepath">日志路径</param>
            /// <param name="filename">日志名称</param>
            /// <param name="content">日志内容</param>
            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常用方法

          本文链接:https://www.haomeiwen.com/subject/fydmottx.html