首 页 ASP ASP.NET PHP JSP Ajax DIV+CSS JavaScript XML C#
MySQL MSSQL Access Oracle Linux Server 电脑技巧 网络安全 建站经验 其它

关于Word文档的数据库存取

整理日期:2007年08月14日 【字体:

本人是将要存取的Word文档信息在数据库中设置成image类型
blob image 16 即为定义的文档变量

////////////////////////////////////////////////////
input a word document into the sql-server storage
notice :
 the type of word document in sql-server database is image
 the table structure in sql-serve
blob表

id int 4 0
name char 50
blob image 16
type char 60

////////////////////////////////////////////////////
  protected void Button1_Click(object sender, EventArgs e)
  {
 //File1 is a component of c# is Fileupload

    Stream imgdatastream = File1.PostedFile.InputStream;
    int imgdatalen = File1.PostedFile.ContentLength;
    string imgtype = File1.PostedFile.ContentType;
    string name = this.File1.PostedFile.FileName;

    byte[] imgdata = new byte[imgdatalen];
    int n = imgdatastream.Read(imgdata, 0, imgdatalen);
    string connstr = "Data Source=LIU;Initial Catalog=YJSBDB;User ID=sa";
    SqlConnection connection = new SqlConnection(connstr);
    SqlCommand command = new SqlCommand("INSERT INTO blob(name,type,blob) VALUES ( @imgtitle, @type,@blob )", connection);
    SqlParameter paramTitle = new SqlParameter("@imgtitle", SqlDbType.VarChar, 50);
    paramTitle.Value = name;
    command.Parameters.Add(paramTitle);
    SqlParameter paramData = new SqlParameter("@blob", SqlDbType.Image);
    paramData.Value = imgdata;
    command.Parameters.Add(paramData);

伊图教程网[www.etoow.com]
http://www.etoow.com/html/2007-08/1187081072.html
    SqlParameter paramType = new SqlParameter("@type", SqlDbType.VarChar, 50);
Tags:
关于Word文档的数据库存取
'http://www.etoow.com/html/2007-08/1187081072.html
1
 
信息搜索
  
联系我们关于本站广告服务设为首页 收藏本站友情链接网站地图
Copyright © Etoow.com Inc. All Rights Reserved