【发布时间】:2017-06-14 16:54:15
【问题描述】:
给定一个带有数据的 SQL 表 Document:
ID Content ByteLength Sequence
1 Part1... 945669 1
1 Part2... 945669 2
1 Part3... 945669 3
...
2 Part1... 45234 1
2 Part2... 45234 2
地点:
Document.Content = Up to 32KB of data
Document.ByteLength = Total data in bytes for the Document ID
Document.Sequence = Order of content in the Document ID
如何将所有Document.Content 读入一个单字节数组byte[] Content?
using (var command = new SqlCommand("SELECT Content FROM Document WHERE ID=1 ORDER BY Sequence", connection))
using (var reader = command.ExecuteReader())
{
while(reader.Read())
{
// What goes here?
// if we just want one row:
//var fileBytes = (byte[])reader.GetValue(0); // read the file data from the selected row (first column in above query)
}
}
【问题讨论】:
-
您可以以追加模式写入二进制文件。 Content 字段的数据类型是什么?
-
前3个序列都是1,不应该是1,2,3吗?
-
@Steve 当前为 varchar(max)。它主要包含 RTF 和 txt 内容。
-
@AlexK。你是对的!已修复。
-
File.AppendAllText 在循环内,当你完成循环 ReadAllText
标签: c# asp.net arrays sqlcommand