日期:2014-05-18 浏览次数:20774 次
//1、转换为字节数组 strImgPath = @"D:\visual studio 2010\Projects\MainPage\Alarm.png"; MemoryStream ms = new MemoryStream(); System.Drawing.Image.FromFile(strImgPath).Save(ms, System.Drawing.Imaging.ImageFormat.Png); ProcParameter[] imgParams = new ProcParameter[1]; imgParams[0] = new ProcParameter("@img", SqlDbType.Image, System.Text.Encoding.Unicode.GetString(ms.GetBuffer()), ParameterDirection.Input); //这里把图片字节数组转换为string(ProcParameter的需要,自定义的一个类), //2、将ProcParameter序列化(xml)由于要传到服务端, SrvProxyAdapter.ExecSql(strSql, PublicMethod.GetStringBySerializeProcParam(imgParams), -1); //ExecSql函数会反序列化imgParams,然后执行,这时候就报错了,说xml文档()出错 public static string GetStringBySerializeProcParam(ProcParameter[] Params) { // 序列化 XmlSerializer xmlFormatter = new XmlSerializer(typeof(ProcParameter[])); StringWriter StrWriter = new StringWriter(); xmlFormatter.Serialize(StrWriter, Params); //传递的参数信息 return StrWriter.GetStringBuilder().ToString(); }