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

真是急得我想哭,拜托各位帮忙

但是最后显示的只有binaryStream1里的值,而不是串联的值?这是为什么啊? 
下面是代码:
 protected void Button3_Click(object sender, EventArgs e)
        {
         /*   word.Application WordApp =new Microsoft.Office.Interop.Word.Application();
            WordApp.Visible = true;
            word.Document WordDoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
            WordDoc.Content.Text = "我会使用了";
            object ofilename = "D:\\1.doc";
            WordApp.ActiveDocument.SaveAs(ref ofilename, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
           // ((word._Document)WordDoc).Close(ref missing, ref missing, ref missing);
           // ((word._Application)WordApp).Quit(ref missing, ref missing, ref missing);
           // System.Runtime.InteropServices.Marshal.ReleaseComObject(WordApp);*/


            SqlBinary binaryStream1 = de("SELECT title  from kan where id=11 ");

            SqlBinary binaryStream2 = de("SELECT title  from kan where id=18 ");
            SqlBinary binaryStream = System.Data.SqlTypes.SqlBinary.Add(binaryStream1, binaryStream2);
            // binaryStream = SqlBinary.Concat(binaryStream2, binaryStream1);
            
            byte[] data = binaryStream.Value;
           
            ByteConvertWord(data,"haokan");
        }

        public SqlBinary de(string str)
        {
            SqlConnection myConnection = new SqlConnection(ConfigurationManager.AppSettings["strcon"]);


            SqlCommand mycommand = myConnection.CreateCommand();
            myConnection.Open();

            mycommand.CommandText = str;  //其中filedata的数据库类型是varbinary(MAX)
            SqlDataReader myReader = mycommand.ExecuteReader();
            myReader.Read();
            SqlBinary binaryStream = myReader.GetSqlBinary(0);//获取指定列值
            // SqlBinary.Concat(x,y);

            myReader.Close();
            myConnection.Close();
            return binaryStream;

        }

       
        /// 将二进制数据转换为word文档 
        /// </summary> 
        /// <param name="data">二进制数据可以直接存放在sql server数据库中的数据</param> 
        /// <param name="fileName">文件名,即你要生成的word文档的名称。自己随便定义一个字符串就行</param> 
        public void ByteConvertWord(byte[] data, string fileName)
        {
            string savePath = @"/Upload/"; //虚拟路径,项目中的虚拟路径。一般我们条用这个方法,肯定要把生成的word文档保存在项目的一个文件夹下,以备后续使用 
            string path = Server.MapPath(savePath); //把相应的虚拟路径转换成物理路径 
            if (!System.IO.Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            savePath += fileName + DateTime.Now.ToString().Replace("-", "").Replace(" ", "").Replace(":", "") + Guid.NewGuid().ToString() + ".doc";
            string filePath = Server.MapPath(savePath);
            FileStream fs;
            if (System.IO.File.Exists(filePath))
            {
                fs = new FileStream(filePath, FileMode.Truncate);
            }
            else
            {
                fs = new FileStream(filePath, FileMode.CreateNew);
            }
            BinaryWriter br = new BinaryWriter(fs);
            br.Write(data, 0, data.Length);
            br.Close();
            fs.Close();
        } --------------------编程问答-------------------- 因为你把驴头装在了马嘴上。以后粘贴代码,记得就着一个地方的复制,别这里搞一点,那里搞一点,不是一个人写的粘在一起不能用很正常。 --------------------编程问答-------------------- 急的想哭不是应该为了保住面子在csdn上发贴问,而是冒着被你boss骂的体无完肤的去问他们解决方法
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,