问题
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