如何将Word文件作为二进制数据存储到SQL Server中 [英] how to store word file as binary data into sql server

查看:123
本文介绍了如何将Word文件作为二进制数据存储到SQL Server中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...


任何人都可以回答...


Hi...


Can anyone Answer...


How to store word file as binary data into sql server.

推荐答案

简单!
将表字段创建为VARBINARY(MAX).
以字节顺序读取文件(直接从您的Upload控件(如果是基于Web的话)或使用File:
Easy!
Create your table field as VARBINARY(MAX).
Read the file as a sequence of bytes (either direct from your Upload control (if this is web based) or by using File:
byte[] bytes = File.ReadAllBytes(path);


然后只需使用参数化查询将其插入:


Then just insert it with a parametrized query:

using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (myDocumentColumn) VALUES (@DOC)", con))
        {
        com.Parameters.AddWithValue("@DOC", bytes);
        com.ExecuteNonQuery();
        }
    }


引用此链接:

http://www.aspsnippets.com/Articles/将文件保存到SQL Server数据库使用FileUpload-Control.aspx [
Refer this link:

http://www.aspsnippets.com/Articles/Save-Files-to-SQL-Server-Database-using-FileUpload-Control.aspx[^]


这篇关于如何将Word文件作为二进制数据存储到SQL Server中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆