孟子E章关于读数据库中图片显示到Web,究竟行不行得通呀??????????????????????????????????????

III_dont_know 2004-12-27 10:08:01
imagename imagelength imagedata
abc.jpg 52441 0x53797374656D2E427974655B5D
...全文
165 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuanqin810616 2004-12-27
  • 打赏
  • 举报
回复
慢慢調試看看有甚麼錯誤嗎?應該可以的
III_dont_know 2004-12-27
  • 打赏
  • 举报
回复
还是不成功http://community.csdn.net/Expert/topic/3678/3678204.xml?temp=7.018679E-02
.html中:
<ItemTemplate>
<asp:Image Runat=server ID="Image1" ImageUrl='<%# FormatURL(DataBinder.Eval(Container.DataItem, "imagename")) %>' />
</ItemTemplate>
.cs中:
protected string FormatURL(object strArgument)
{
DataSet ds=new DataSet();
DataTable dt=new DataTable();
ds.Tables.Add(dt);

string conn="Data Source=hkserver;Integrated Security=SSPI;Initial Catalog=useraccounts;User ID=sa;Password=";
SqlConnection myConnection = new SqlConnection(conn);
SqlDataAdapter adp1=new SqlDataAdapter("SELECT imagename,imagedata FROM InImage where imagename='"+strArgument.ToString()+"'",myConnection);
adp1.Fill(ds,"dt");
byte[] MyData= new byte[0];

MyData = (byte[])ds.Tables["dt"].Rows[0][1];
Response.ContentType= "image/*";
Response.BinaryWrite (MyData);
}
yuanqin810616 2004-12-27
  • 打赏
  • 举报
回复
頭文件要包含;

using System.Data.OleDb;
using System.Data.SqlClient ;
yuanqin810616 2004-12-27
  • 打赏
  • 举报
回复
//把資料庫裡面的資料讀出來轉成二進制,然後輸出,給你做參考
string strConnString = "Provider=OraOLEDB.Oracle.1;Password=" + Password + ";Persist Security Info=True;User ID=" + LoginID + ";Data Source=" + ServerName + ";Extended Properties=";

OleDbDataAdapter MYDA = new OleDbDataAdapter();
OleDbCommand myCommand = new OleDbCommand("SELECT LABOR_PHOTO FROM LBM.LABOR_INFO_EMP WHERE LABOR_ID=(SELECT LABOR_ID FROM LBM.LABOR_INFO WHERE LABOR_NO='"+ LABOR_NO +"')", myConnection);

MYDA.SelectCommand = myCommand;
myCommand.Connection.Open();
MYDA.Fill(MYDS);
byte[] MyData= new byte[0];
DataRow myRow;
myRow=MYDS.Tables[0].Rows[0];

MyData = (byte[])myRow["LABOR_PHOTO"];
Response.ContentType= "image/*";
Response.BinaryWrite (MyData);
Truly 2004-12-27
  • 打赏
  • 举报
回复
sure
liuwei662656 2004-12-27
  • 打赏
  • 举报
回复
肯定是行得通的。
不只图片。
WORD. EXCEL什么的也可以。
直接输出。

111,096

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧