Display BLOB file in DocumentViewer

允我心安 提交于 2020-01-17 07:00:14

问题


I have a column of type BLOB in my MySQL database which stores various files. I am trying to select a file based on the fileNo specified by the user in a comboBox and display the file in the documentViewer (component by Xtreme DocumentStudio package). Here is the code that I have already:

string connection = "server=127.0.0.1; database=business;user=root; password=root01;";
MySqlConnection connect = new MySqlConnection(connection);

connect.Open();

MySqlCommand myCmd = new MySqlCommand();

myCmd.Connection = connect;

myCmd.CommandText = "SELECT fileSubmitted FROM files WHERE fileNo = @fileNo;";

DataRowView drv = (DataRowView)comboBox4.SelectedItem;
int fileNo = Convert.ToInt32(drv[comboBox4.DisplayMember].ToString());
myCmd.Parameters.AddWithValue("@fileNo", fileNo);

byte[] bits = new byte[0];
bits = (byte[])myCmd.ExecuteScalar();
MemoryStream ms = new MemoryStream(bits);
documentViewer1.LoadDocument(ms);

When I run the code I receive the error:

An exception of type 'System.ArgumentNullException' occurred in mscorlib.dll but was not handled in user code
Additional information: `Buffer cannot be null.`

on the line: MemoryStream ms = new MemoryStream(bits);

I have been trying my best to solve this issue but not had any luck. I am not sure what I have already is remotely close to the solution or whether I am not indeed far off. Any help would be very much appreciated.

来源:https://stackoverflow.com/questions/28636869/display-blob-file-in-documentviewer

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!