-1

我需要将 Ms Word 文件的文本转换为二进制文件并将其存储在数据库中。我也设法打开了文件和 TrackRevisions。如何将 MS Word 文本保存在数据库中并将其检索回来并在 MS Word 中显示

4

1 回答 1

1

您可以将文件内容存储到二进制/varbinary 字段(SQL Server 中允许的最大长度为 8000)。

使用参数插入/更新数据库。这里 ac# 示例:

将文本文件存储到 MS SQL 数据库中

//reading the file content
FileStream s = new FileStream(filePath, FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[s.Length];
s.Read(buffer, 0, s.Length);
s.Close();

//adding a row in the database
SqlCommand insertCommand = new SqlCommand("insertCommand into myTable (binaryField) values (@filedata)", youconnection);
insertCommand.Parameters.Add(new SqlParameter ("@filedata", buffer ));
insertCommand.ExecuteNonQuery();

检索在 sql server 数据库中加载为二进制数据的 msword 文件

于 2013-01-04T06:20:37.383 回答