您的位置:首页 > 编程语言 > ASP

asp.net 把word转化成二进制文件存储到数据库

2012-04-30 20:02 507 查看
int flieLength = FileUpload1.PostedFile.ContentLength;
Stream fs = FileUpload1.PostedFile.InputStream;
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, flieLength);
using (SqlConnection con = new SqlConnection("Data Source=localhost;database=test;uid=sa;pwd=123"))
{
con.Open();
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "insert into T_files(files) values(@file)";
SqlParameter spFile = new SqlParameter("@file", SqlDbType.Image);
spFile.Value = bytes;
cmd.Parameters.Add(spFile);
cmd.ExecuteNonQuery();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: