在Sql server中存取word文件!

sql表结构自动生成word文档 将SQL SERVER数据库表结构自动生成word文档,速度快,效率高 立即下载

/*如何把word存入sqlserver数据库,并且读取的时候还是用word读取.
建立table
create table myimages(sno int,imgfield image);
建立c#工程,添加引用(reference->add->brower->office安装文件夹->office11->msword.ole,然后什么都不用问了,等待...,然后拷贝下代码,具体功能见注释*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using System.IO;

namespace writeFile
{
 /// <summary>
 /// Summary description for Form1.
 /// </summary>
 public class Form1 : System.Windows.Forms.Form
 {
  private System.Windows.Forms.Button button1;
  private System.Windows.Forms.TextBox textBox1;
  private System.Windows.Forms.Button button2;
  private System.Windows.Forms.Button button3;
  /// <summary>
  /// Required designer variable.
  /// </summary>
  private System.ComponentModel.Container components = null;

  public Form1()
  {
   //
   // Required for Windows Form Designer support
   //
   InitializeComponent();

   //
   // TODO: Add any constructor code after InitializeComponent call
   //
  }

  /// <summary>
  /// Clean up any resources being used.
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows Form Designer generated code
  /// <summary>
  /// Required method for Designer support - do not modify
  /// the contents of this method with the code editor.
  /// </summary>
  private void InitializeComponent()
  {
   this.button1 = new System.Windows.Forms.Button();
   this.textBox1 = new System.Windows.Forms.TextBox();
   this.button2 = new System.Windows.Forms.Button();
   this.button3 = new System.Windows.Forms.Button();
   this.SuspendLayout();
   //
   // button1
   //
   this.button1.Location = new System.Drawing.Point(576, 320);
   this.button1.Name = "button1";
   this.button1.Size = new System.Drawing.Size(112, 23);
   this.button1.TabIndex = 0;
   this.button1.Text = "saveFiletoDb";
   this.button1.Click += new System.EventHandler(this.button1_Click);
   //
   // textBox1
   //
   this.textBox1.Location = new System.Drawing.Point(0, 0);
   this.textBox1.Multiline = true;
   this.textBox1.Name = "textBox1";
   this.textBox1.Size = new System.Drawing.Size(568, 424);
   this.textBox1.TabIndex = 1;
   this.textBox1.Text = "textBox1";
   //
   // button2
   //
   this.button2.Location = new System.Drawing.Point(600, 104);
   this.button2.Name = "button2";
   this.button2.TabIndex = 2;
   this.button2.Text = "readWord";
   this.button2.Click += new System.EventHandler(this.button2_Click);
   //
   // button3
   //
   this.button3.Location = new System.Drawing.Point(568, 184);
   this.button3.Name = "button3";
   this.button3.Size = new System.Drawing.Size(112, 23);
   this.button3.TabIndex = 3;
   this.button3.Text = "readFromDb";
   this.button3.Click += new System.EventHandler(this.button3_Click);
   //
   // Form1
   //
   this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
   this.ClientSize = new System.Drawing.Size(712, 429);
   this.Controls.Add(this.button3);
   this.Controls.Add(this.button2);
   this.Controls.Add(this.textBox1);
   this.Controls.Add(this.button1);
   this.Name = "Form1";
   this.Text = "Form1";
   this.Load += new System.EventHandler(this.Form1_Load);
   this.ResumeLayout(false);


  }
  #endregion

  /// <summary>
  /// The main entry point for the application.
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new Form1());
  }

  private void button1_Click(object sender, System.EventArgs e)//把word存入sqlserver
  {
     DbMana dm=new DbMana();
   SqlConnection con=dm.GetCon();//另外的类,返回sqlserver连接,用的时候要自己建立连接

   
   SqlDataAdapter comm=new SqlDataAdapter("select * from MyImages",con);
   SqlCommandBuilder scb=new SqlCommandBuilder(comm);//只有这样才能保证dataadapter可以update
   DataSet ds=new DataSet("MyImages");
   comm.Fill(ds,"MyImages");
   comm.MissingSchemaAction=MissingSchemaAction.AddWithKey;
   DataRow newRow;
   newRow=ds.Tables[0].NewRow();
   FileStream fs=new FileStream(@"E:/club.doc",FileMode.Open,FileAccess.Read);
   byte[] data=new byte[fs.Length];
   fs.Read(data,0,Convert.ToInt32(fs.Length));//文件读到byte[]
   fs.Close();
   comm.Fill(ds,"MyImages");
   newRow["id"]=3;
   newRow["description"]="this is a file";
   newRow["imgField"]=data;//insert the binary stream
   ds.Tables["MyImages"].Rows.Add(newRow);
   comm.Update(ds,"MyImages");//update,then the table is update
   con.Close();

   /*try
   {
    con.Open();
    ds.Tables[0].Rows[0]["content"]=data;
   }
   catch(Exception ex)
   {
    this.textBox1.Text=ex.ToString();


   }
   finally
   {
    fs.Close();
    con.Close();

   }*/

  
  }

  private void Form1_Load(object sender, System.EventArgs e)
  {
   
  }

  private void button2_Click(object sender, System.EventArgs e)//read the word file
  {
      object nothing=System.Reflection.Missing.Value;
     object filename=@"E:/club.doc";
   Word.ApplicationClass ap=new Word.ApplicationClass();
      Word.Document doc=ap.Documents.Open(ref filename,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing,ref nothing);
   
   ap.Visible=true;
      
   
  
  }

  private void button3_Click(object sender, System.EventArgs e)//read from table,and临时存放,便于读取然后可以删掉
  {
   DbMana dm=new DbMana();
  SqlConnection con=dm.GetCon();
   //SqlCommand com=new SqlCommand("select imgfield from myimages",con);
   DataSet ds=new DataSet();
   SqlDataAdapter comm=new SqlDataAdapter("select imgfield from myimages",con);
   SqlCommandBuilder scb=new SqlCommandBuilder(comm);
   byte[] data=new byte[0];
      comm.Fill(ds,"myimages");
   DataRow newRow;
   newRow=ds.Tables["myimages"].Rows[3];
   data=(byte[])newRow["imgField"];
   int arraysize=new int();//注意这句话
   arraysize=data.GetUpperBound(0);

   FileStream fs=new FileStream(@"e:/test.doc",FileMode.OpenOrCreate,FileAccess.Write);
   try
   {
    
    
    fs.Write(data,0,arraysize);
   }
   catch(Exception ex)
   {
    this.textBox1.Text=ex.ToString();

   }
   finally
   {
    con.Close();
    fs.Close();
    
   }

   
   
  
  }
 }
}

精通sql(虽说是word格式但是排版极好阅读) 学些sql的好资料,请多多下载!!!! 里面是分章节的,一个word 是一章 !! 立即下载

相关推荐

把sql表里面的数据导出到word里面

把sql里面的数据导出到word文档里面去,看网上例子,自己写的,需要导入office组件

C#实现在Sql Server中存储和读取Word文件

要实现在Sql Server中实现将文件读写Word文件,需要在要存取的表中添加Image类型的列,示例表结构为: CREATE TABLE CONTRACTS ( ID VARCHAR (50), CONTRACT_FILE IMAGE ); 要将Word文件存储到数据库的CONTRACT_FILE字段中,需要将文件转换为byte数组,具体代码如下: 将文件转换为byt

落日小屋 9176

word导入sql

如何通过 java 语言 从 jsp 页面上的数据 导入 word 里 如果你的数据形式是以 表格显示的 是可以的 直接把 jsp 中 table 内容导出到 word 或 excel

C#读取word文档文本

读取word,首先得添加引用,不同的word版本对应着不同的引用部分版本对应引用如下:Microsoft Word 11.0 object library对应Office2003Microsoft Word 12.0 object library对应Office2007Microsoft Word 14.0 object library对应Office2010Microsoft Word 15.0...

zxy13826134783的博客 2万+

麒麟操作系统Kylin如何从 2203 升级到 2403

fill:#333;important;important;fill:none;color:#333;color:#333;important;fill:none;fill:#333;height:1em;开始升级流程第一步:升级前准备1. 确认版本为 V10 SP1 22032. 备份全部重要数据3. 确保网络稳定4. 关闭应用第二步:选择升级方式方法一:图形界面升级方法二:命令行升级1. 更新现有系统至最新2. 启动“系统升级”工具3. 检测并开始下载2403。

让编程变的很简单!! 2714

C++ 类

本文介绍了C++中类的核心概念和使用方法。

weixin_54859557的博客 1019

Sql Server 生成 Word 文档 表结构

Sql Server 生成 Word 文档 表结构

shan1774965666的专栏 1820

保姆级避坑指南:在Ubuntu 18.04上搞定速腾Helios雷达驱动与fast-LIO2的完整配置流程

本文提供了一份详细的速腾Helios雷达与fast-LIO2在Ubuntu 18.04上的配置避坑指南,涵盖驱动安装、数据格式转换到建图全流程。特别针对常见编译错误和数据转换问题提供了解决方案,帮助开发者高效完成环境搭建与建图任务。

weixin_27252001的博客 117

C 实现在Sql Server中存储和读取Word文件

C 实现在Sql Server中存储和读取Word文件

qq_44929357的博客 943

【AUTOSAR-DCM】-3.1-将CDD导入CFG并查看$22服务配置变化(UDS诊断DID带一个Data)

案例背景:(共8页精讲) 在《【UDS诊断描述文件CDD】-3.2-编辑CDD给$22服务创建一个带一个Data的DID(dataIdentifier)数据标识符》中,适应使用CANdela Studio在CDD中创建一个带一个Data的DID(dataIdentifier)数据标识符,见图0-1。现在我们将该CDD文件导入到CFG(DaVinci Configurator),看看配置会发生哪些变化。 图0-1 目录 1 将诊断描述文件CDD导入CFG(DaVinci Configurator.

「汽车电子助手」的博客 1636

SAP SLT DMIS 2018_1_752 究竟是什么意思?

把读懂,并不需要背太多编号。你只要记住:它就是DMIS 2018发行线里、面向的那一档组件版本,承载SLT 3.0的功能集。面向项目落地,要点就是三件事:看清平台基线、对齐DMIS支持包、走官方安装与补丁路径。如此,S/4到HANA,抑或S/4到BigQuery的复制链路,都会变得既稳定又可维护。DMIS 2018是新技术发行,基于,覆盖SLT全场景(SAP Learning)。DMIS_2018的安装与下载路径、通过SAINT安装的官方步骤(Installation Guide PDF)。源系统与。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 228

word文档的mysql数据库类型_关于word文档的数据库存取

本人是将要存取的Word文档信息在数据库中设置成image类型blob image 16 即为定义的文档变量////////////////////////////////////////////////////input a word document into the sql-server storagenotice :the type of word document in sql-serv...

weixin_39922004的博客 800

UE5实现建筑剖切效果

UE5实现建筑剖切效果

专注GIS开发 8470

关于word文档的数据库存取

本人是将要存取的Word文档信息在数据库中设置成image类型blob image 16 即为定义的文档变量////////////////////////////////////////////////////input a word document into the sql-server storage notice :the type of word document in s...

dba5032的博客 214

clock min pulse width检查

高电平脉宽 = clock fall edge到达FF/CK的时间 - clock rise edge到达FF/CK的时间;低电平脉宽 = 下一T clock rise edge到达FF/CK的时间 - clock fall edge到达FF/CK的时间。而required pulse width是根据FF/CK处的transition,根据查找表计算得到的。为什么clock transition越大,会导致required pulse width越大呢?5、 降低clock上的串扰。

芯冰乐 589

(SEED-Lab)Buffer Overflow Vulnerability Lab缓冲区溢出实验

(SEED-Lab)Buffer Overflow Vulnerability Lab 欢迎大家访问我的GitHub博客 https://lunan0320.cn 文章目录一、实验目的二、实验步骤与结果2.1 环境初始化2.2 Task1 运行shellcode2.3漏洞程序2.4 Task 22.5 Task 3: ASLR2.6 Task 4: Stack Guard2.7 Task 5:不可执行栈三、参考文献 一、实验目的 理解缓冲区溢出攻击的原理以及如何实施攻击 理解针对缓冲区溢出的防御措施

lunan的博客 8989

数据库 自带_Wincc 如何连接SQL Server 数据库

经常会有朋友用到将部分有用的数据单独写到关系型数据库如:SQL Server ,MySQL等,然后通过制作报表进行数据的显示,而对于报表,我目前比较常用的是 SQL Server 自带的免费的 SSRS 来制作报表,用户可以通过网页的形式进行访问,页可以导出为PDF,WORD,或者可以选择打印,非常方便。那么对于WINCC软件大家肯定非常熟悉了,那么,如何将实时数据写入WINCC自带的关系数据库S...

weixin_30840919的博客 5744

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

C# 读取数据库word 和写入数据库word文件

要实现在Sql Server中实现将文件读写Word文件,需要在要存取的表中添加Image类型的列,示例表结构为: CREATE TABLE CONTRACTS ( ID VARCHAR (50), CONTRACT_FILE IMAGE ); 要将Word文件存储到数据库的CONTRACT_FILE字段中,需要将文件转换为byte数组,具体代码如下: 将文件转

zhgyuhui的专栏 2491

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

通过SQL SERVER远程上传文件的实现[原创]

我记得有一种黑客工具,在得到对方SQL SERVER服务器的SA帐号和密码后竟可以通过它上传文件到对方 服务器上面,并远程执行DOS命令。当时觉得很好奇,当然作为程序员的我觉得很不爽, 赶快对SQL SERVER进行了一番研究,并整理出了这篇文章,希望对一些程序新手会有帮助。 写过数据库程序的朋友应该知道,我们可以往数据库中存取各种类型的资料数据 比如文本,整型,二进制等数据。 ...

weixin_30838873的博客 384

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

[转] C#实现在Sql Server中存储和读取Word文件 (Not Correct Modified)

出处C#实现在Sql Server中存储和读取Word文件 要实现在Sql Server中实现将文件读写Word文件,需要在要存取的表中添加Image类型的列,示例表结构为: 1 2 3 4 CREATETABLECONTRACTS ( IDVARCHAR(50), CONTRACT_FI...

weixin_34177064的博客 150

往SQL Server中存入word文档,然后用bcb把它读出

存入   TStream  *nrStream;   m_adoTable->Edit();   nrStream->LoadFromFile(strFromPath);   tmpField  =  (TBlobField  *)m_adoTable->FieldByName("StwordCon");   tmpField->LoadFromStream(nrStream);

403
下一篇: c#.net函数和方法集(转载)
BestSky
博客等级 码龄23年 5粉丝 27原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址