首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

错在哪儿了为什么读取出来打开word里面只显示:System.Byte[]这几个字

2013-03-27 
错在哪里了为什么读取出来打开word里面只显示:System.Byte[]这几个字//word文件上传按钮private void butt

错在哪里了为什么读取出来打开word里面只显示:System.Byte[]这几个字

        //word文件上传按钮
        private void button2_Click(object sender, EventArgs e)

        {
            OleDbConnection Conn;
            Conn = new OleDbConnection(StartWindow.StrConn);
            Conn.Open();
            string location = textBox1.Text;
            string[] argLocation= location.Split(new Char[] {'\\'});
            int i = argLocation.Length;
            linkLabel1.Text = argLocation[i-1];

            System.IO.FileStream fs = new System.IO.FileStream(@location,System.IO.FileMode.Open);
            fs.Position = 0;
            byte[] content = new byte[fs.Length];
            fs.Read(content, 0, (int)fs.Length);
            fs.Close();
           // OleDbDataAdapter da;
            string strUpdate = "update Base_TAnswerFile set DeviationTable='" + content + "',ItemInformation='招标项目信息'";
       
            OleDbCommand cmd = new OleDbCommand(strUpdate,Conn);
            cmd.CommandText = strUpdate;

            cmd.ExecuteNonQuery();
            cmd.Dispose(); 
            Conn.Close();
            Conn.Dispose();
            Conn.Close();

        }


  private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            //读取二进制文件转化为word文档
            string filePath = "E:\\test.doc";
            string fileName = filePath;
            if (System.IO.File.Exists(fileName))
            {
                System.IO.File.Delete(fileName);
            }
            //OleDbDataAdapter da;


            OleDbConnection Conn;
            Conn = new OleDbConnection(StartWindow.StrConn);
            Conn.Open();
            //da = new OleDbDataAdapter(@"select DeviationTable from Base_TAnswerFile ", Conn);
            OleDbCommand com = Conn.CreateCommand();
            //DataSet testDataSet = new DataSet();
            //da.Fill(testDataSet, "Base_TAnswerFile");
            com.CommandText = "select DeviationTable from Base_TAnswerFile";
            byte[] content = (byte[])com.ExecuteScalar();//读取之后转换成二进制字节数组
            System.IO.FileStream fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create);
            fs.Write(content, 0, content.Length);
            fs.Flush();
            fs.Close();
            Conn.Close();
        }


[解决办法]
string?strUpdate?=?"update?Base_TAnswerFile?set?DeviationTable='"?+?content?+?"',ItemInformation='招标项目信息'";
不能这么插入数据库
string?strUpdate?=?"update?Base_TAnswerFile?set?DeviationTable=@content,ItemInformation='招标项目信息'";
cmd.Parameters.Add("@content",content);
这样

热点排行