[英]Download File from BLOB Oracle using c#
i have created simple project in c# to save file data into Oracle Database using BLOB data type and it worked. 我已经在c#中创建了一个简单项目,使用BLOB数据类型将文件数据保存到Oracle数据库中,并且它可以正常工作。 i used devexpress gridcontrol to show the data. 我用devexpress gridcontrol来显示数据。 This is the sample data that i have created. 这是我创建的示例数据。
in the btnDownload will download data from blob oracle that i selected row. 在btnDownload中,将从我选择的行的blob oracle下载数据。 here is my code: 这是我的代码:
var rowHandle = gridView1.FocusedRowHandle;
var obj = gridView1.GetRowCellValue(rowHandle, "FILENAME");
if(koneksidb.con.State == ConnectionState.Open)
{
koneksidb.con.Close();
}
koneksidb.con.Open();
OracleCommand cmd = new OracleCommand();
OracleDataReader dr;
cmd.CommandText = @"SELECT * FROM LATIHANFILEMANAGER WHERE FILENAME='"+ obj +"'";
cmd.Connection = koneksidb.con;
dr = cmd.ExecuteReader();
while(dr.Read())
{
UInt32 FileSize = Convert.ToUInt32(dr.GetInt32(dr.GetOrdinal("FILESIZE"))); //get file size from table LATIHANFILEMANAGER
rawData = new byte[FileSize];
var nilai = dr.GetBytes(dr.GetOrdinal("FILEDATA"), 0, rawData, 0, (int)FileSize); //this file that i wanna download
FileStream fls = new FileStream(@"D:\newfile.png", FileMode.OpenOrCreate, FileAccess.Write);
fls.Write(rawData, 0, (int)FileSize);
fls.Close();
}
dr.Close();
when i run this project and download the image, i got a file and file size but it cannot be opened. 当我运行该项目并下载图像时,我得到了文件和文件大小,但无法打开。
here is the file that i captured: 这是我捕获的文件:
this tutorial i got from this link: https://docs.oracle.com/cd/E17952_01/connector-net-en/connector-net-programming-blob-reading.html 我从以下链接获得了本教程: https : //docs.oracle.com/cd/E17952_01/connector-net-en/connector-net-programming-blob-reading.html
any suggest? 有什么建议吗?
first, you show your Image(BLOB) from database to PictureBox, than use SaveFileDialog. 首先,将您的Image(BLOB)从数据库显示到PictureBox,然后使用SaveFileDialog。 for more information visit How to use saveFileDialog for saving images in C#? 有关更多信息,请访问如何使用saveFileDialog在C#中保存图像?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.