在DocumentViewer中显示BLOB文件

时间:2015-02-20 19:37:16

标签: c# mysql sql blob

我的MySQL数据库中有一个BLOB类型的列,用于存储各种文件。我试图根据用户在comboBox中指定的fileNo选择一个文件,并在documentViewer(由Xtreme DocumentStudio包组件)中显示该文件。这是我已经拥有的代码:

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);

当我运行代码时,我收到错误:

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

就行:MemoryStream ms = new MemoryStream(bits);

我一直在努力解决这个问题,但没有运气。我不确定我已经远远接近解决方案,或者我是否确实离我很远。非常感谢任何帮助。

0 个答案:

没有答案