2013-01-04 50 views
-1

我需要一個Word文件女士的文本轉換爲二進制並將其存儲在數據庫中。我設法打開文件和TrackRevisions也。我如何保存在數據庫中的MS Word文本,並在MS Word中檢索並展示其字MS文本到二進制

+0

SQL服務器?哪個版本? –

+0

SQL Server 2005中 – Ankur

回答

1

您可以存儲文件內容爲二進制/ VARBINARY場(允許SQL Server中的最大長度爲8000)。

使用參數來插入/更新數據庫。這裏一個C#示例:

Storing Text file into MS SQL database

//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(); 

Retrieving msword file loaded as binary data in sql server database

+1

請您總結一下在你的答案的鏈接的內容。也http://meta.stackexchange.com/questions/8231 –

+0

見它是如何工作的?我只需要存儲它的文本,並且如果在保存整個修改後的數據時所做的更改應該保存在數據庫中。基本上我不想下載文件。只是想給用戶的設備打開,編輯和恢復回到DB – Ankur

+1

@Ankur文件:請記住,這是一個編程網站,所以你得到的答案最有可能會是代碼。 –