日期:2014-05-19  浏览次数:20776 次

恳请高手看一下源代码,看问题出在哪。急!
我做的是在数据库中存储调用图片,除窗体程序外添加了个类getdata.cs,代码如下:
using   System;
using   System.Data;
using   System.Data.SqlClient;
using   System.Drawing;
using   System.IO;

namespace   OrderClient.Forms
{
///   <summary>
///   getdata   的摘要说明。
///   </summary>
public   class   image_query
{
string   image_filename   =   null;
byte[]   image_bytes   =   null;
SqlConnection   image_connection   =   null;
SqlCommand   image_command   =   null;
SqlDataReader   image_reader   =   null;
//constructor   initializes   connection,
//command,   and   reader   objects
public   image_query()
{

image_connection   =   new   SqlConnection(
@ "Data   Source=(local); "   +
"Integrated   Security   =   SSPI; "   +
"Initial   Catalog   =   Tube; "       +
"Connect   Timeout   =   3 ");
image_command   =   new   SqlCommand(
@ "SELECT   imagefile,imagedata   FROM   imagetable ",
image_connection);
//
//   TODO:   在此处添加构造函数逻辑
//
//open   the   connection   and   read   data   into   the   Datareader
image_connection.Open();
image_reader   =   image_command.ExecuteReader();



}
public   Bitmap   get_image()
{
MemoryStream   ms   =   new   MemoryStream(image_bytes);
Bitmap   bmap   =   new   Bitmap(ms);
return   bmap;
}
public   string   get_filename()
{
return   image_filename;
}
public   bool   get_row()
{
if(image_reader.Read())
{
image_filename   =   (string)   image_reader.GetValue(0);
image_bytes   =   (byte[])   image_reader.GetValue(1);
return   true;
}
else
{
return   false;
}


}
public   void   end_query()
{
//Close   the   reader   and   the   connection
image_reader.Close();
image_connection.Close();


}
}
}
运行后没有报错,但出现异常:未处理的“System.Data.SqlClient.SqlException”类型的异常出现在   system.data.dll   中。

其他信息:   系统错误。中止在image_reader   =   image_command.ExecuteReader();

我是参考书上的例子做的,在下实在愚钝,恳请专家指点

------解决方案--------------------
用try{} catch{} 把错误取出来看看
------解决方案--------------------
其他信息: 系统错误。中止在image_reader = image_command.ExecuteReader();
-----------
1说明已经连接完成,在reader的时候终止了。可以用其他简单数据测试下连接
2仔细看下是不是数据问题