本人是将要存取的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);
关于Word文档的数据库存取
'http://www.etoow.com/html/2007-08/1187081072.html