如何将Word文档导入到SQL Server
问题描述:
请在C#.net中提供确切的代码,以将Excel工作表,Word文档导入到SQL Server.请帮帮我.....
Please give exact code in C#.net to import excel sheet,word document in to sql server. please help me out please.....
答
否.但这并不困难:
1)在数据库中设置一个字段来保存它:IMAGE是一个要使用的字段,因为VARBINARY只能容纳8000个字节.
2)使用 File.ReadAllBytes [ ^ ]
3)连接到数据库,然后使用参数化的INSERT sql语句将字节写入数据库:
No. But it isn''t difficult:
1) Set up a field in your database to hold it: IMAGE is the one to go for as VARBINARY can only hold 8000 bytes.
2) Read the file, using File.ReadAllBytes[^]
3) Connect to your database, and write the bytes to it using a parametrized INSERT sql statement:
using (SqlCommand cmd = new SqlCommand("INSERT INTO MyTable (wordFile) VALUES (@DATA)", con))
{
cmd.Parameters.AddWithValue("@DATA", data);
cmd.ExecuteNonQuery();
}