我正在编写将一个SQL表(其中包含2个文本/ int字段和一个图像类型字段)导出到csv文件的代码。一切正常,除非我无法将图像文件成功写入字符串。这是我目前的这部分代码:查询SQL图像数据类型并输出到字符串
string selectDocRows = "SELECT ID,Name FROM Documents WHERE ID=" + DocumentID;
SqlCommand selectFileData = new SqlCommand("SELECT FileData FROM Documents WHERE ID=" + DocumentID,SQLConnection);
using (SqlDataAdapter DocAdapter = new SqlDataAdapter(selectDocRows, SQLConnection))
{
using (DataTable DocTable = new DataTable("DocumentResults"))
{
DocAdapter.Fill(DocTable);
foreach (DataRow row in DocTable.Rows)
{
string DocRow = string.Format("{0},{1},", row[0], row[1]);
byte[] DocPDF = (byte[])selectFileData.ExecuteScalar() ;
CSVText.AppendLine(DocRow + DocPDF);
}
}
}
,用于返回字节[]所谓DocPDF结果是:
1,ChatLog立即开会2016_12_13 12_26.pdf,System.Byte []
3列:索引,文件名和文件内容
但不是真正的文件内容,我只是得到 “System.Byte []”
当执行单个sql查询并将第三列转换为字符串时,我会得到相同的结果。我需要(也会期待)我在SQL查询中看到的127,000个字符。相反,我只是得到“System.Byte []”
任何帮助,将不胜感激。