当前位置:编程学习 > C#/ASP.NET >>

将整个excel文件存入MSSQL数据库中的image字段后,下载后不能打开


这是为什么呢?
其他如图片、word都可以打开 --------------------编程问答--------------------

#region 打开电机各类文档
        /// <summary>
        /// 打开电机各类文档
        /// </summary>
        /// <param name="fileName">文档的名称</param>
        /// <param name="procName">存储过程名</param>
        /// <param name="fieldFileName">存储文档名称的字段名</param>
        /// <param name="fieldFile">存储文档的字段名</param>
        private void openFile(string fileName, string procName,string fieldFileName,string fieldFile)
        {
            dataSet = SqlHelper.ExecuteDataset(SqlHelper.connStr, CommandType.StoredProcedure, procName, new SqlParameter(fieldFileName, fileName));
            table = dataSet.Tables[0];
            string path = @"C:\Users\Administrator\Desktop\ " + fileName;
            using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write))
            {
                foreach (DataRow row in table.Rows)
                {
                    byte[] fileByte = (byte[])row[fieldFile];
                    int arraySize = fileByte.GetUpperBound(0);
                    fs.Write(fileByte, 0, arraySize);
                    Process.Start(path);
                }   
            } 
        }
        #endregion

--------------------编程问答-------------------- 上面是我下载的源代码 --------------------编程问答--------------------

using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                        {
                            byte[] motorSPLByte = new byte[Convert.ToInt32(fileStream.Length)];
                            fileStream.Read(motorSPLByte, 0, (int)fileStream.Length);
                            SqlHelper.ExecuteNonQuery(sqlTran, CommandType.StoredProcedure, "proc_insertSPLDecument", new SqlParameter("motorName", this.txtMotorName.Text),
                                new SqlParameter("@sPLName", fileName), new SqlParameter("@sPLDecument", motorSPLByte));
                        }

这是我上传整个excel文件的部分代码
补充:.NET技术 ,  .NET Framework
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,