【发布时间】:2010-09-29 12:22:26
【问题描述】:
此方法返回一些奇怪的结果,想知道是否有人可以解释为什么会发生这种情况,并且可能是获得我想要的结果的解决方案。
结果:
文件名 = 我的期望
FileSize = 我的期望
缓冲区 = 所有字节 = 0
BytesRead = 0
BlobString = 二进制数据字符串
FieldType = BLOB(我所期望的)
ColumnType = System.String
此外,如果文件大于几 KB,阅读器会抛出异常,指出 StringBuilder 容量参数必须大于零(可能是因为大小大于 Int32.MaxValue)。
我想我的问题是如何正确地从 OdbcDataReader 读取大型 BLOB?
public static String SaveBinaryFile(String Key)
{
try
{
Connect();
OdbcCommand Command = new OdbcCommand("SELECT [_filename_],[_filesize_],[_content_] FROM [_sys_content] WHERE [_key_] = '" + Key + "';", Connection);
OdbcDataReader Reader = Command.ExecuteReader(CommandBehavior.SequentialAccess);
if (Reader.HasRows == false)
return null;
String FileName = Reader.GetString(0);
int FileSize = int.Parse(Reader.GetString(1));
byte[] Buffer = new byte[FileSize];
long BytesRead = Reader.GetBytes(2, 0, Buffer, 0, FileSize);
String BlobString = (String)Reader["_content_"];
String FieldType = Reader.GetDataTypeName(2);
Type ColumnType = Reader.GetFieldType(2);
return null;
}
catch (Exception ex)
{
Tools.ErrorHandler.Catch(ex);
return null;
}
}
【问题讨论】:
标签: c# sqlite blob datareader