惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
博客园 - 【当耐特】
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Recent Announcements
Recent Announcements
D
Docker
GbyAI
GbyAI
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
The Cloudflare Blog
雷峰网
雷峰网
A
About on SuperTechFans
小众软件
小众软件
博客园 - Franky
博客园 - 聂微东
F
Full Disclosure
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
MongoDB | Blog
MongoDB | Blog
G
Google Developers Blog
Microsoft Azure Blog
Microsoft Azure Blog
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V
V2EX
Engineering at Meta
Engineering at Meta
宝玉的分享
宝玉的分享
aimingoo的专栏
aimingoo的专栏
量子位
P
Proofpoint News Feed
Hugging Face - Blog
Hugging Face - Blog
博客园_首页
罗磊的独立博客
Martin Fowler
Martin Fowler
D
DataBreaches.Net
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
S
Secure Thoughts
Project Zero
Project Zero
L
LangChain Blog
阮一峰的网络日志
阮一峰的网络日志
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tailwind CSS Blog
S
Schneier on Security
Blog — PlanetScale
Blog — PlanetScale
The Hacker News
The Hacker News
Spread Privacy
Spread Privacy
Security Latest
Security Latest
NISL@THU
NISL@THU
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
CXSECURITY Database RSS Feed - CXSecurity.com
J
Java Code Geeks

博客园 - huazi4995

prototype.js开发笔记 JS应用 java环境配置 关于梅花雪的js树 - huazi4995 - 博客园 MagicAjax的使用 - huazi4995 - 博客园 div+css制作的选项卡 - huazi4995 - 博客园 SQL查询语句精华使用简要 - huazi4995 - 博客园 身份证号码验证-支持新的带x身份证 c#常用函数和方法集汇总 动态创建层 C#操作Word文档(Office 2007) datagrid控件使用技巧大集合 网站设计常用技巧 jsp编程技巧 ArrayList的使用方法(转载) 将datagrid里的资料导入到excel js中的小技巧 ajax+xml数据岛,增加编辑与删除按钮 利用webservice实现省、市的无刷新
关于word文档的数据库存取
huazi4995 · 2007-07-13 · via 博客园 - huazi4995

////////////////////////////////////////////////////
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);
        SqlParameter paramType 
= new SqlParameter("@type", SqlDbType.VarChar, 50);
        paramType.Value 
= imgtype;
        command.Parameters.Add(paramType);
        connection.Open();
        
int numRowsAffected = command.ExecuteNonQuery();
        connection.Close(); 
    }


//////////////////////////////////////////////////////////////
output the word document from sql-server database 
//////////////////////////////////////////////////////////////
    protected void Page_Load(object sender, EventArgs e)
    
{
        
string imgid = this.Request.QueryString.Get("ID");
        
//Request.QueryString["imgid"]; 
        string connstr = "Data Source=LIU;Initial Catalog=YJSBDB;User ID=sa";
        
string sql = "SELECT name,blob, type FROM blob ";
        SqlConnection connection 
= new SqlConnection(connstr);
        SqlCommand command 
= new SqlCommand(sql, connection);
        connection.Open();
        SqlDataReader dr 
= command.ExecuteReader();
        
if (dr.Read())
        
{
            Response.Clear();
            Response.Buffer 
= true;
            Response.Charset 
= "GB2312";
            Response.ContentEncoding 
= System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
            
//Response.ContentType = "application/ms-word";//设置输出文件类型为word文件。
            Response.ContentType = dr["type"].ToString();
            Response.BinaryWrite((
byte[])dr["blob"]);
            
string FileName = dr["name"].ToString().Trim();
            FileName 
= System.Web.HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8);
            Response.AppendHeader(
"Content-Disposition""attachment;filename=" + FileName);
        }

        connection.Close(); 
    }


http://www.cnblogs.com/liulanglang/archive/2007/06/25/794617.aspx