FileStream fs=new FileStream(path1,FileMode.Create,FileAccess.ReadWrite);
           con = new SqlConnection("data source=spd;initial catalog=exam;user id=sa;password=123");
           da = new SqlDataAdapter("select * from sj_table", con);
           SqlCommandBuilder cb = new SqlCommandBuilder(da);
           con.Open();
           ds = new DataSet();
           da.Fill(ds, "sj");
           byte[] rtf1 =(byte[])ds.Tables["sj"].Rows[0][2];
           byte[] rtf2 = (byte[])ds.Tables["sj"].Rows[1][2];
           byte[] rtf3 = (byte[])ds.Tables["sj"].Rows[2][2];
           int len1 = rtf1.Length;
           int len2 = rtf2.Length;
           int len3= rtf3.Length;
          fs.Write(rtf1, 0, len1);
          fs.Write(rtf2, 0, len2);
          fs.Write(rtf3, 0, len3);
           fs.Close();
           con.Close();
为什么在WORD 里只是显示了第一条记录,后两条没有显示啊

解决方案 »

  1.   

    byte[] buffer = new byte[len1+len2+len3];
    rtf1.CopyTo(buffer,0);
    rtf2.CopyTo(buffer,len1);
    rtf3.CopyTo(buffer,len1+len2);
    fs.Write(buffer, 0, len1+len2+len3);
      

  2.   

    lz试试这个,应该可以的,加上"\r\n"就会换行的
                FileStream fs = new FileStream(path1, FileMode.Create, FileAccess.ReadWrite);
                con = new SqlConnection("data source=spd;initial catalog=exam;user id=sa;password=123");
                da = new SqlDataAdapter("select * from sj_table", con);
                SqlCommandBuilder cb = new SqlCommandBuilder(da);
                con.Open();
                ds = new DataSet();
                da.Fill(ds, "sj");
                byte[] rtf1 = (byte[])ds.Tables["sj"].Rows[0][2];
                byte[] rtf2 = (byte[])ds.Tables["sj"].Rows[1][2];
                byte[] rtf3 = (byte[])ds.Tables["sj"].Rows[2][2];            byte[] buf;            buf = new byte[rtf1.Length + 2];
                rtf1.CopyTo(buf, 0);
                (Encoding.ASCII.GetBytes("\r\n")).CopyTo(buf, rtf1.Length);
                fs.Write(buf, 0, buf.Length);            buf = new byte[rtf2.Length + 2];
                rtf2.CopyTo(buf, 0);
                (Encoding.ASCII.GetBytes("\r\n")).CopyTo(buf, rtf2.Length);
                fs.Write(buf, 0, buf.Length);            buf = new byte[rtf3.Length + 2];
                rtf3.CopyTo(buf, 0);
                (Encoding.ASCII.GetBytes("\r\n")).CopyTo(buf, rtf3.Length);
                fs.Write(buf, 0, buf.Length);
    lz还可以使用StreamWriter的WriteLine方法,也可以实现换行
                StreamWriter sw = new StreamWriter(fs);
                sw.WriteLine("123");
      

  3.   

    FileStream fs =new Filestream(……);
    StreamWriter sw =new StreamWriter(fs);sw.writeLine(……);sw.Flush();sw.Close();
    fs.Close();
      

  4.   

    你写什么格式的文件?filestream能处理格式? shupingda() ( ) 信誉:100    Blog  2006-12-11 22:02:32  得分: 0  
     
     
       笑看人生,我试了你的方法,不行的,读出来只有一条,我数据库里存的是数据与图象混合的
      
     
      

  5.   

    int len1 = rtf1.Length;
    int len2 = rtf2.Length;
    int len3 = rtf3.Length;
    fs.Write(rtf1, 0, len1);
    fs.Write(rtf2, len1+1, len2);
    fs.Write(rtf3, len1 + len2 +1, len3);不知道这样行不行
      

  6.   

    用这个换行:vbCrLf 试下。
      

  7.   

    调用Close方法前调用Flush方法。
      

  8.   

    LZ
    你每次都从开始的地方写,肯定不可以了想个办法换行吧如:
    FileStream fs =new Filestream(……);
    StreamWriter sw =new StreamWriter(fs);sw.writeLine(……);