gpt4 book ai didi

c# - 获取MySql数据库中的blob文件

转载 作者:行者123 更新时间:2023-11-29 08:14:52 24 4
gpt4 key购买 nike

我正在尝试从MySql获取Blob(winWord doc.存储在MySql中)文件。一切正常,但当我尝试打开它时,MSWORD 告诉我该文件的内容有问题。这是我的代码:

myConn.Open();
MySqlDataReader myReader;
long CurrentIndex = 0;
long BytesReturned;

using (myReader = view.ExecuteReader())
{
while (myReader.Read())
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
string strFilename = saveFileDialog1.FileName;
FileStream fs = new FileStream(strFilename, FileMode.OpenOrCreate, FileAccess.ReadWrite);
BinaryWriter bw = new BinaryWriter(fs);
CurrentIndex = 0;
long len = 100;
byte[] blob = new byte[len];
int id = myReader.GetOrdinal("word");
BytesReturned = myReader.GetBytes(id, CurrentIndex, blob, 0, (int)len);

while (BytesReturned == (int)len)
{
bw.Write(blob);
bw.Flush();
CurrentIndex += (int)len;
BytesReturned = myReader.GetBytes(id, CurrentIndex, blob, 0, (int)len);


}
bw.Write(blob, 0, (int)len - 1);
bw.Flush();
bw.Close();
fs.Close();

}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

提前致谢。

最佳答案

以下文档建议您在数据库中存储和检索文件

http://dev.mysql.com/doc/refman/5.5/en/connector-net-programming-blob.html

关于c# - 获取MySql数据库中的blob文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20836307/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com