经常有人说,在递归中连接数据库是大忌,但是一般如何解决呢。。
我要从数据库中提取2张照片显示。。我的写法是这样的,能改成更优方法吗
protected void Page_Load(object sender, EventArgs e)
{
string kk = Request.Params[ "addictno "];
Image aa = (Image)FormView1.FindControl( "Image1 ");
Image bb = (Image)FormView1.FindControl( "Image2 ");
aa.ImageUrl = GetPicPath(kk);
bb.ImageUrl = GetPicPath2(kk);
}
private string GetPicPath(string addictNo)//取第一张
{
//建立数据库链接
OracleConnection conn = new OracleConnection( "连接 ");
OracleCommand Oraclecomm = new OracleCommand();
Oraclecomm.CommandText = "SELECT pic FROM zpb WHERE rybh = ' " + addictNo + " ' ";
Oraclecomm.Connection = conn;
OracleDataAdapter da = new OracleDataAdapter(Oraclecomm);
DataSet ds = new DataSet();
conn.Open();
da.Fill(ds, "zpb ");
conn.Close();
Response.Clear();
//将图片数据存成本地文件
string tempfile = " " + addictNo + "&num=1.jpg ";
string fpath = Server.MapPath(Request.ApplicationPath) + "\\informaintiom\\temp\\ " + tempfile;
FileStream fs = new FileStream(fpath, FileMode.OpenOrCreate, FileAccess.Write);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write((byte[])ds.Tables[ "zpb "].Rows[0][0]);
bw.Close();
return "../informaintiom/temp/ " + tempfile;
}
private string GetPicPath2(string addictNo)//取第二张
{
//建立数据库链接
OracleConnection conn = new OracleConnection( "连接 ");