public void sqltofile(string str_table_name,string str_blob_column_name,string str_select_condition)
{
//数据库操作
SqlDataReader sdr_file;
string str_scn=ConfigurationSettings.AppSettings["str_database_connection"];
cyc_data cd_file=new cyc_data(str_scn);

//构造检索语句
string str_scm="select " + str_blob_column_name + " from " + str_table_name +
" where " + str_select_condition;
SqlCommand scd_file=new SqlCommand(str_scm,cyc_data.scn_databaseconnection);
if (cyc_data.scn_databaseconnection.State==ConnectionState.Closed)
{
try
{
cyc_data.scn_databaseconnection.Open();
}
catch (SqlException e)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Redirect("error.aspx?id=1");
HttpContext.Current.Response.End();
}
}

//执行查询
try
{
sdr_file=scd_file.ExecuteReader(CommandBehavior.SequentialAccess);
}
catch (SqlException e)
{
sdr_file=null;
cyc_data.scn_databaseconnection.Close();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Redirect("error.aspx?id=2");
HttpContext.Current.Response.End();
}

//读出文件内容
if (sdr_file.Read())
{
try
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType=open_file_application(file_type(str_table_name,str_blob_column_name,str_select_condition));
System.IO.Stream fs=HttpContext.Current.Response.OutputStream;
int fileDataCol = 0; 
Byte[] b = new Byte[(sdr_file.GetBytes(fileDataCol, 0, null, 0, int.MaxValue))];
sdr_file.GetBytes(fileDataCol, 0, b, 0, b.Length);
sdr_file.Close();
cyc_data.scn_databaseconnection.Close();
string s = System.Text.Encoding.Default.GetString(b);
fs.Write(b,0,b.Length);
fs.Close();
HttpContext.Current.Response.End();
}
catch (Exception e)
{
//关闭数据库连接
sdr_file.Close();
cyc_data.scn_databaseconnection.Close();
//打开错误提示页
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Redirect("error.aspx?id=5");
HttpContext.Current.Response.End();
}
}
//无法读取或者没有符合条件记录
else
{
sdr_file.Close();
cyc_data.scn_databaseconnection.Close();
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Redirect("error.aspx?id=2");
HttpContext.Current.Response.End();
}
}