//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();
        }

解决方案 »

  1.   

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

  2.   

    多谢!!这分都给你了。
    用cmd.Parameters.Add("@content",content);提示过时
    用下面这个不提示了,多谢!!
     cmd.Parameters.AddWithValue("@content", content);