Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在DocumentViewer中显示BLOB文件_C#_Mysql_Sql_Blob - Fatal编程技术网

C# 在DocumentViewer中显示BLOB文件

C# 在DocumentViewer中显示BLOB文件,c#,mysql,sql,blob,C#,Mysql,Sql,Blob,我的MySQL数据库中有一个BLOB类型的列,它存储各种文件。我试图根据用户在组合框中指定的fileNo选择一个文件,并通过Xtreme DocumentStudio包在documentViewer组件中显示该文件。以下是我已经掌握的代码: string connection = "server=127.0.0.1; database=business;user=root; password=root01;"; MySqlConnection connect = new MySqlConnect

我的MySQL数据库中有一个BLOB类型的列,它存储各种文件。我试图根据用户在组合框中指定的fileNo选择一个文件,并通过Xtreme DocumentStudio包在documentViewer组件中显示该文件。以下是我已经掌握的代码:

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=新的MemoryStream位


我一直在尽力解决这个问题,但没有任何运气。我不确定我已经拥有的东西离解决方案还有一段距离,或者我是否真的离它不远。非常感谢您提供的任何帮助。

首先,如果您只对第[0][0]行感兴趣,则无需为DataAdapter或DataTable操心。您应该能够使用bits=byte[]myCmd.ExecuteScalar;之类的东西;。此外,在请求代码帮助时,请确保包括实际结果、行为、错误消息等。。。。我有。。。我一点运气都没有。没有特别的信息。对不起,可能是含糊不清的问题戈尔。我已经修改了我的代码以包含您提到的语句,并删除了DataAdapter和DataTable,我得到以下错误:mscorlib.dll中发生了类型为“System.ArgumentNullException”的异常,但未在用户代码中处理其他信息:缓冲区不能为null。我已经编辑了上面的代码,请您的问题显示您从上面的评论中收到的错误消息,并告诉我们哪行代码引发了异常。好的,我现在编辑了问题您是否验证select语句将返回数据?在我看来,您的查询没有返回任何数据-这就是为什么位为空,因此MemoryStream的构造函数失败!